'Node JS session error: express-session deprecated
I have the following in my node js file
var express = require('express');
var util = require('./lib/utility');
var partials = require('express-partials');
var bodyParser = require('body-parser');
var session = require('express-session');
/* abstracted some code */
app.use(session({
genid: function(req) {
return genuuid(); // use UUIDs for session IDs
},
secret: 'keyboard cat'
}));
When I start the server, I get
express-session deprecated undefined resave option; provide resave option server.js
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option server.js
I am having a hard time figuring out what is deprecated? I copied the example from https://github.com/expressjs/session
When I try to load the page I get:
ReferenceError: genuuid is not defined at app.use.session.genid
Solution 1:[1]
From express 4.0 , express-session with odd warning message
As the warnings say, the default values will change so they want to ensure that by setting the values explicitly now, you won't run into unexpected behavior when the defaults do change (in the near future).
app.use(session({
secret: cookie_secret,
resave: true,
saveUninitialized: true
}));
Solution 2:[2]
Add these flags-
resave: true,
saveUninitialized: true
inside your - app.use(session({});
and it should work fine.
Solution 3:[3]
Use this , hope it will help
app.use(session({
name : 'codeil',
secret : 'something',
resave :false,
saveUninitialized: true,
cookie : {
maxAge:(1000 * 60 * 100)
}
}));
Solution 4:[4]
Add
{
resave: true,
saveUninitialized: true
}
to your session middleware
Solution 5:[5]
app.use(session({ secret: 'anything', resave: true, saveUninitialized: true }));/
Solution 6:[6]
if you are using maxAge for session cookie duration:
app.use(session({
secret: '<session_secret>',
resave: true,
saveUninitialized: true,
maxAge: 3600000 // 1 hour (in milliseconds)
}));
Solution 7:[7]
You have to use a new version of express and define genid function somewhere in your app or use uuid package instead
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darryl Snow |
| Solution 2 | Uvuvwevwevwe |
| Solution 3 | Federico Cristina |
| Solution 4 | atline |
| Solution 5 | Stephen Rauch |
| Solution 6 | Gajen Sunthara |
| Solution 7 | mohamed ibrahim |
