Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: I can't make connect-redis work with express

This is my code :

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

And this is the error I get :

  RedisStore.prototype.__proto__ = Store.prototype;
                                        ^
TypeError: Cannot read property 'prototype' of undefined
    at module.exports (/home/cherif/Bureau/Twimbee/server/gamma/node_modules/connect-redis/lib/connect-redis.js:96:41)
    at Object.<anonymous> (/home/cherif/Bureau/Twimbee/server/gamma/index.js:2:42)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Please help

like image 780
Cherif Avatar asked Dec 02 '22 16:12

Cherif


2 Answers

Looks like they've addressed this in their docs:

Due to express 4.x.x changes, we now need to pass express-session to the function connect-redis exports in order to extend express-session.Store:

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

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

https://github.com/visionmedia/connect-redis under usage

like image 91
Matt Pileggi Avatar answered Dec 23 '22 05:12

Matt Pileggi


1) remove express from node_modules

2) clean the cache (npm cache clean)

3) install the last version via package.json (*) or npm install

4) install connect-redis via package.json or npm install

5) Use:

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

like image 21
Alexandre Vieira Avatar answered Dec 23 '22 05:12

Alexandre Vieira