npm i --save connect-mongodb-session
MongoDB session store for Connect and Expressgit
const mongoose = require('mongoose'); const session = require('express-session'); const MongoStore = require('connect-mongo')(session); const url = 'mongodb://localhost:27017/NodeServer'; const options = { autoReconnect: true }; mongoose.connect(url, options); const database = mongoose.connection; const sessionStore = new MongoStore({mongooseConnection: database, collection: 'sessions'}); const sessionOptions = { secret: 'secret_key_hahaha', name: 'session_id', store: sessionStore, resave: false, saveUninitialized: false, cookie: { maxAge: 1000 * 60 * 60, } };