I am using express to develop a simple website.
I just get confused about how to make the nodejs check session before rendering any page, so that if a user did not login, he cannot see anything.
I think in rails it is quite simple, just add some codes in the application controller. But how to handle such thing in nodejs?
Define a middleware function to check for authentication before your routes and then call it on each of your routes. For example in your app.js
Then call this pass this method in your routes (notice the authenticate parameter):