Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Cannot start connect-redis with Express 4.12.2

I am using express 4.12.2, express-session 1.11.1, & connect-redis 1.4.7. When running the following code with NODE_ENV=production npm start:

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

app.use(session({
  store: new RedisStore(options),
  secret: 'keyboard cat'
}));

I receive the following error:

 var Store = connect.session.Store;
                            ^
 TypeError: Cannot read property 'Store' of undefined

Any help would be greatly appreciated.

like image 429
pleo93 Avatar asked Nov 27 '25 16:11

pleo93


1 Answers

1.4.7 is a pretty old version of connect-redis. The signature has changed since that version. Before it accepted a connect object, but since the 2.0 update with express 4 it now accepts a session object. Your code is already using the new signature so for this to work all you should need to do is update your package.json

...
"dependencies": {
    ...
    "connect-redis": "^2.3.0"
}
...

and/or update the module in place:

npm install connect-redis
like image 184
Andrew Lavers Avatar answered Nov 29 '25 11:11

Andrew Lavers