How to store session values with Node.js and mongodb?

前端 未结 2 1441
甜味超标
甜味超标 2020-12-29 14:19

How do I get sessions working with Node.js, express@2.0.0 and mongodb? I\'m now trying to use connect-mongo like this:

var config = require(\'../config\'),
          


        
2条回答
  •  萌比男神i
    2020-12-29 14:52

    I am not experienced with Node.js or Express, so I cannot immediately see what's wrong with your approach. However, I have made Express use MongoDB to store sessions for flash messages and other session stuff.

    You can see my source code for a simple URL shortener here (that actually makes the URLs pretty long at the moment - it was just an exercise ;)). I use the session to store a list of URLs that the current user has shortened.

    It is not pretty, but I know it works.

提交回复
热议问题