Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express 4.0 , express-session with odd warning message

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 ?

like image 230
jmls Avatar asked Jun 29 '14 14:06

jmls


People also ask

What is Express () function?

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.

Is Express session secure?

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.

What is Express session resave?

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.

Does Express session use cookies?

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.


2 Answers

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).

like image 98
mscdex Avatar answered Sep 19 '22 18:09

mscdex


I found issue useful:

https://github.com/expressjs/session/issues/56

app.use(session({     secret: cookie_secret,     resave: true,     saveUninitialized: true })); 
like image 24
Ben Avatar answered Sep 20 '22 18:09

Ben