I am trying to understand sessions. I know their purpose and i know that they are saved on the server. Now, i'd like to "see" them so i can see what informations they contain. Is there a way to access the sessions on the server as i can see the cookies with a browser ?
CodePudding user response:
Assuming you're using express-session, you look in req.session
on an incoming request for a particular user. You put something into a session by assigning properties to req.session
on an incoming request. And, then on future requests whatever data on put in the session will be in req.session
on future requests.
If you want to just examine everything in the session store, then you have to go to the interface for whatever session store you're using and use that. If you haven't selected a specific session store when configuring express-sesssion
, then it's using the memoryStore.
To have general access to the session store, you'd have to create your own session store, save it somewhere and then provide it to the express-session initialization options.
Within a given request req.sessionStore
is the active session store object which has an interface documented in the express-session doc. But, inside a specific request, you would usually just access req.session
to access the current user's session data.
If you want to know more about how any of the dozens of supported session stores work, you'd have to console their doc/code.