Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 505
Arian Faurtosh Avatar asked Aug 30 '25 15:08

Arian Faurtosh


2 Answers

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
}));
like image 126
Darryl Snow Avatar answered Sep 16 '25 03:09

Darryl Snow


You have to define the genuuid function somewhere. The express-session readme is assuming you have already implemented that.

Regarding the warnings, you need to explicitly set the resave and saveUninitialized options in your session configuration object.

like image 35
mscdex Avatar answered Sep 16 '25 03:09

mscdex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!