Robert M Robert M - 3 months ago 37
Node.js Question

Node automatically makes session variables?

I am using express with the express-session package and can successfully keep a session variable like such,

router.get('/test', function(req, res, next){
req.session.test = 'awesome';

and when I use the code below I will get the desired result

router.get('/pest', function(req, res, next){


I do not have an issue, but I am having trouble understanding, does Node automatically create sessions with other variables? for example:

router.get('/test', function(req, res, next){
router.test = 'test';

then going to

router.get('/lest', function(req, res, next){

makes the same exact result. It seems odd that node will automatically keep the variable like that after some time.


It isn't a session variable.

You have a single router object.

Modifications to it will persist for every request, not just those that come from a browser with a given session cookie.