As suggested by another user; using Redis is a perfectly acceptable solution to this problem.
The disadvantage of this is the use of the service to store session objects and middleware. As mentioned earlier, this is useful in cases of node process restart, failure, etc. Saving session data in a node process carries risks. One of the benefits of using microposts (like Redis) is that these risks are reduced.
Assuming you're using Express for your middleware, you can use something called the Session store . There are many modules that use this feature.
One of these connect-redis modules
Installation is as usual:
npm install connect-redis express-session
Then you will use it like this:
var session = require('express-session') var RedisStore = require('connect-redis')(session) app.use(session({ store: new RedisStore(options), secret: 'keyboard cat' }))
Now you are using your session object as usual. ( req.session )
<strong> Examples:
To set session information (for example, from a POST form):
req.session.email = req.body.email
To get session information:
console.log( req.session.email )
source share