Session store

ninemoonz·2022년 7월 26일


목록 보기

Problem with session

Session is created when a browser first reachs to a backend. And browser only gets the sessionID. Problem is that the default server-side session storage is a MoemoryStore. Means it is volatile. It will perish whenever the backend restart or the server dies. (Not designed for a product environment)
more info


Saves the session in the mongoDB.

  1. Install connect-mongo package through terminal
    npm i connect-mongo
  2. Import MongoStore in the server.js
    import MongoStore from "connect-mongo";
  3. Write command lines on the app.use(session)
    secret: "Hello",
    resave: true,
    saveUninitialized: true,
    store: MongoStore.create({mongoUrl: "mongodb://"}),
  • This creates a sessions db in our MongoDB.
  • When a browser interact with the backend, the sessionID given to the browser will be stored in the db.
On a journey to be a front-end developer

0개의 댓글