Quiz Entry - updated: 2026.06.20
How do you set up sessions in Express.js?
Register the express-session middleware with a secret key that signs the session cookie.
import session from 'express-session';
app.use(session({ secret: '<largeStringValue>' }));
- secret: Used to sign the session cookie, preventing tampering
- Sessions are automatically created when needed
- Access via
req.session - Get session ID with
req.session.id