Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Session Storage Middleware for Express + MongoDB

I was looking for the best middleware for storing session data in MongoDB to use in a production application that uses express?

I've been looking around and found this:

  1. session-mongoose (https://github.com/donpark/session-mongoose) According to author's comment this is not production-ready for following reasons:

    • insufficient testing
    • zero optimization
    • there are better options than MongoDB for session storage
  2. connect-mongo (https://github.com/kcbanner/connect-mongo)

  3. express-session-mongo (https://github.com/davglass/express-session-mongo)

    Based on these classes

    • Sencha Connect Memory Store
    • ciaranj's express-session-mongodb
  4. connect-session-mongo (https://github.com/bartt/connect-session-mongo)

I've been looking at their code, I was trying to find also a performance comparisson article. Do you guys have experience to suggest which is the best?

like image 463
Crisboot Avatar asked Dec 27 '12 17:12

Crisboot


People also ask

How do I store session data express?

The express-session package have inbuilt method to set, get and destroy session. Step 1: Create a folder 'node-express-session' and go to the folder path, Now create package dependency file using npm. Above command will create package. json file into 'node-express-session' folder.

Is express session secure?

If you run with https and your physical computer is secure from outsiders, then your express session cookie is protected from outsiders when stored locally and is protected (by https) when in transport to the server.

What is session middleware?

The session middleware handles all things for us, i.e., creating the session, setting the session cookie and creating the session object in req object. Whenever we make a request from the same client again, we will have their session information stored with us (given that the server was not restarted).

What is the difference between express session and cookie session?

Cookie session is basically used for lightweight session applications where the session data is stored in a cookie but within the client [browser], whereas, Express Session stores just a mere session identifier within a cookie in the client end, whilst storing the session data entirely on the server.


2 Answers

connect-mongo (https://github.com/kcbanner/connect-mongo) looks better then others.

express-session-mongo and connect-session-mongo are very old and based on old version of mongodb driver.

session-mongoose based on mongoose, that slower than mongodb driver.

I think connect-mongo is the best choose.

like image 167
Vadim Baryshev Avatar answered Sep 22 '22 20:09

Vadim Baryshev



connect-mongodb-session

  • https://www.npmjs.com/package/connect-mongodb-session
  • Published 3 months ago
  • connect-mongodb-session: MongoDB-backed session storage for connect and Express. Meant to be a well-maintained and fully-featured replacement for modules like connect-mongo
  • Google also now shows this one first.

connect-mongo

  • https://www.npmjs.com/package/connect-mongo
  • Published a year ago

like image 37
Manohar Reddy Poreddy Avatar answered Sep 22 '22 20:09

Manohar Reddy Poreddy