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:
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
connect-mongo (https://github.com/kcbanner/connect-mongo)
express-session-mongo (https://github.com/davglass/express-session-mongo)
Based on these classes
- Sencha Connect Memory Store
- ciaranj's express-session-mongodb
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?
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.
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.
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).
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.
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.
connect-mongodb-session
connect-mongo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With