In here we will try to mange session in node application.
Here are the dependencies which is used in this sample
"dependencies":
{
"express": "^4.8.7",
"express-session": "^1.7.6"
}
express-session module needs express. Therefore you have to add express in your project also.
var express = require('express');
var session = require('express-session');
var app = express();
session can be initialized by below code. Here ‘secret‘ is used for cookie handling
app.use(session({secret: 'secret cat'}));
After creating Session, Session variables can be introduced as 'appsession.username'.
var appsession;
app.get('/',function(req,res){
appsession=req.session;
appsession.username;
});
No comments:
Post a Comment