node.js - Express JS 4: exported routes and session -


i'm quite new node , i've been working through issue hours failing @ finding solution :/ perhaps u can me :)

i have exported routes out of app.'s routes.js. there having post login-process. when loged in, want pass userid databank session later use (e.g. socket io). how have construct this? have tried several setups don't seem it.

app.js

var cookieparser = require('cookie-parser'); var session = require('express-session'); var sessionstore = new session.memorystore(); app.use(cookieparser('lts session')); app.use(session({ secret: 'lts session', cookie: { maxage: 600000 }, store : sessionstore})); var router = require('./modules/routes.js'); app.use(router); 

routes.js

router.post('/', function(req, res) {     ....     req.session.name =  admins[id].name;     req.session.userid = id;     ... }; 

later on control session logging sessionstore.

if u manipulate session-vars, use:

req.session.save() 

this save session-manipulation. example:

router.post('/', function(req, res) {   ....   req.session.name =  admins[id].name;   req.session.userid = id;   req.session.save()   ... }; 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -