Sessions
Install express-session
npm i express-sessionSetup the session module
// at the very top, require express-session
const session = require('express-session');
/*
* setup the session with the following:
*
* secret: A string used to "sign" the session ID cookie, which makes it unique
* from application to application. We'll hide this in the environment
*
* resave: Save the session even if it wasn't modified. We'll set this to false
*
* saveUninitialized: If a session is new, but hasn't been changed, save it.
* We'll set this to true.
*/
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}));Session finished
Last updated