Welcome aboard! We are happy you are here and wish you good net-raft!
// at first you must install npm install node-session
var http = require('http');
var NodeSession = require('node-session');
http.createServer(function (req, res) {
callback = function () {
};
session = new NodeSession({secret: 'Q3UBzdH9GEfiRCTKbi5MTPyChpzXLsTD'});
session.startSession(req, res, callback); // start the Session
req.session.put('mysession', 'Hello'); // set the Session
var value = req.session.get('mysession'); // get the Session
if (value) {
res.write("<p>your session's value is: <b>" + value + "</b></p>");
} else {
res.write('<p>Session is not set!</p>');
}
res.end();
}).listen(3000);
console.log("Listening to Port 3000");
// Removing An Item From The Session
req.session.forget('mysession');
//Removing All Items From The Session
req.session.flush();
The most helpful NODEJS solutions
get user ipNODEJS Click to see more ... 7.6K 1.7K