I am trying to work through setting up a nodejs app using express 4.x. After stumbling through the middleware-removal issues, I finally got it working.
however, there was a couple of warning messages in the following line of code :
app.use(session({secret: '<mysecret>'})
these warnings were :
Sun, 29 Jun 2014 12:45:10 GMT express-session deprecated pass resave option; default value will change at lib\config\express.js:55:11 Sun, 29 Jun 2014 12:45:10 GMT express-session deprecated pass saveUninitialized option; default value will change at lib\config\express.js:55:11
in the documentation, the default values for resave and saveUninitialized are true.
so, changing the code to read
app.use(session({secret: '<mysecret>', saveUninitialized: true, resave: true}));
got rid of the warnings.
So, to get to the point of the question:
why should I have to pass these values in if they are the default values, and why don't I have to pass in the other options ?
Express provides methods to specify what function is called for a particular HTTP verb ( GET , POST , SET , etc.) and URL pattern ("Route"), and methods to specify what template ("view") engine is used, where template files are located, and what template to use to render a response.
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.
resave : It basically means that for every request to the server, it reset the session cookie. Even if the request was from the same user or browser and the session was never modified during the request.
Here is a simple explanation: - A user session can be stored in two main ways with cookies: on the server or on the client. express-session stores only a session identifier on the client within a cookie and stores the session data on the server, typically in a database.
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).
I found issue useful:
https://github.com/expressjs/session/issues/56
app.use(session({ secret: cookie_secret, resave: true, saveUninitialized: true }));
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