Wednesday, June 3, 2015

Node Application with Session

Sessions allow you to keep user's data when they visit your application. This post will continue with the implementations done in my last post.
First you need to add express-session middleware.
The express-session module will use a cookie-stored, signed identifier to identify the current user. To sign the session identifier, it will use a secret  string, which will help prevent malicious session tampering. Configure development.js file like below.
Now, configure your express application to use session middleware. The session middleware adds a session object to all request objects in your application. Using this session object, you can set or get any property that you wish to use in the current session.
In index.server.controller.js file add current date time into a session variable called, lastVisit.
Browse for http://localhost:3000/. In developer tools, session tab you will see a session cookie has added.

No comments:

Post a Comment