Simple session manager for nodejs.
Starts and tracks user sessions. A session is kept acitive for 24 minutes after last request. Expired sessions are cleared every hour.
Just import the module.
const session = require('./simple-node-session.js');
const server = http.createServer((req, res) => {
session.start(req,res);
});
const server = http.createServer((req, res) => {
session.start(req,res);
session.set('user',{id:12,name:'Jonh'});
session.get('user'); //returns {id:12,name:'John'}
Session.get('person') // returns null
});
const server = http.createServer((req, res) => {
session.start(req,res);
session.set('user',{id:12,name:'Jonh'});
session.set('user2', {id:11,name:'Smith'});
Session.remove('user');
session.get('user'); //returns null
session.get('user2'); //returns {id:11,name:'Smith'}
});
const server = http.createServer((req, res) => {
session.start(req,res);
session.set('user',{id:12,name:'Jonh'});
session.set('user2', {id:11,name:'Smith'});
Session.clear();
session.get('user'); //returns null
session.get('user2'); //returns null
});
const server = http.createServer((req, res) => {
session.start(req,res);
session.getId(); //example output: 15462993004401260632411303441255082165051805156267545744228041233671277163233824562443261074464378433044351882158
});
Stores session data in a json object. This Object can get large in memory with thousands of active sessions.