Reputation: 762
I want to create sessions for multiple login for same account now i am storing unique session strings for any particular users now my question is that when i was using express-session then on its documentation page enter link description here it's mentioned that
Warning: The default server-side session storage, MemoryStore, is purposely not designed for a production environment. It will leak memory under most conditions, does not scale past a single process, and is meant for debugging and developing
Now my question is that as i am creating an app for business should i use it or not and if i dont use then what will be best for storing sessions i have heard about redis but i have also heard that it consumes much memory that's why can anyone please put some ligt on this i will be really greateful.
Upvotes: 2
Views: 694
Reputation: 4783
The common three more useful options instead MemoryStore
:
From here
I suggest you use CookieSession
, because is more simple and fast. Simple example from docs:
var cookieSession = require('cookie-session')
var express = require('express')
var app = express()
app.set('trust proxy', 1) // trust first proxy
app.use(cookieSession({
name: 'session',
keys: ['key1', 'key2']
}))
Time for expiry:
maxAge: a number representing the milliseconds from Date.now() for expiry
expires: a Date object indicating the cookie's expiration date (expires at the end of session by default).
You can set either expires or maxAge on the individual cookie belonging to the current user:
// This user should log in again after restarting the browser
req.session.cookie.expires = false;
// This user won't have to log in for a year
req.session.cookie.maxAge = 365 * 24 * 60 * 60 * 1000;
Upvotes: 1