I know we can create session using Express JS using following,
express.session({ secret: 'secret' });
But I don't want to use any framework. Just only with Node-JS, how can we create session and maintain it?
You can check out node-sessions. I have not used it, but after skimming it's home page it looks like you don't need to use any framework.
I do it the following way. I store the session information retrieved from the form into the redis database. You can use something like the one given to store the session information.
var json= JSON.parse(body.toString());
exchange.addUserSession(redisClient,json.userID,json.sessionID,function(err, response){
console.log(response);
res.end(response.toString());
redisClient.quit();
});
And then something like this to actually store the session information in the database.
exports.addUserSession = function (redisClient,userId,sessionId,callback){
//add the user and its session in appsession hash map in redis
redisClient.hset('appsession',sessionId,userId,function(err,response){
callback(err,response);
});
};
Hope it helps