Express Sessions
express-session middleware
Install
Require in server.js
or app.js
Use
Save user information on the session object
For each of the routes you create, the req
variable will now have a session
property which is itself an object. You can assign new properties to this object.
Retrieve user information saved on the session object
Once you add a property to the session object, you can retrieve it when a user navigates to any other route. Then you can use it to make decisions based on the design of your application. Remember though, this session will end when the user closes their browser, or you restart your app.
Destroy the session
You can destroy a session before a user closes their browser window.
Session Store
In server.js
or app.js
Last updated
Was this helpful?