node.js - Can't use connect-redis in Express.js -
i'm studying express.js , learned how handle sessions using cookie-session module. i'm trying use express-session have problems.
previously, using cookie-session instead of express-session, , memorystore worked perfectly. however, couldn't use connect-redis cookie-session, reason installed express-session, it, can't use sort of store, nor memorystore neither redis.
the redis db on redistogo , uri looks this: (masked security although practice) redis://redistogo:e34d3***********************f4bb@albacore.redistogo.com:10072/
however, when run "node app", prints error.
my package.json:
{ "name": "application-name", "version": "0.0.1", "author": "me <me@gmail.com>", "license": "mit", "private": true, "scripts": { "start": "node app" }, "dependencies": { "express": "4.x.x", "cookie-parser": "1.x.x", "express-session": "1.x.x", "connect-redis": "2.x.x" } }
the "npm ls" show following:
├─┬ connect-redis@2.0.0 │ ├── debug@0.8.0 │ └── redis@0.10.1 ├─┬ cookie-parser@1.0.1 │ ├── cookie@0.1.0 │ └── cookie-signature@1.0.3 ├─┬ express@4.0.0 │ ├─┬ accepts@1.0.0 │ │ ├── mime@1.2.11 │ │ └── negotiator@0.3.0 │ ├── buffer-crc32@0.2.1 │ ├── cookie@0.1.0 │ ├── cookie-signature@1.0.3 │ ├── debug@0.8.0 │ ├── escape-html@1.0.1 │ ├── fresh@0.2.2 │ ├── merge-descriptors@0.0.2 │ ├── methods@0.1.0 │ ├── parseurl@1.0.1 │ ├── path-to-regexp@0.1.2 │ ├── qs@0.6.6 │ ├── range-parser@1.0.0 │ ├─┬ send@0.2.0 │ │ └── mime@1.2.11 │ ├─┬ serve-static@1.0.1 │ │ └─┬ send@0.1.4 │ │ ├── fresh@0.2.0 │ │ ├── mime@1.2.11 │ │ └── range-parser@0.0.4 │ ├─┬ type-is@1.0.0 │ │ └── mime@1.2.11 │ └── utils-merge@1.0.0 └─┬ express-session@1.0.3 ├── buffer-crc32@0.2.1 ├── cookie@0.1.2 ├── cookie-signature@1.0.3 ├── debug@0.7.4 ├── uid2@0.0.3 └── utils-merge@1.0.0
my app.js:
//create express app var http = require('http'); var express = require('express'); var app = express(); //add express-session var session = require('express-session'); var redisstore = require('connect-redis')(express); app.use(session({ store: new redisstore({ host: "redis://redistogo:e34d3***********************f4bb@albacore.redistogo.com:10072/" }) })); //routing var router1 = require('./router/router1')(app); var router2 = require('./router/router2')(app); //deploying server http.createserver(app).listen(3000, function () { console.log('deployed!!'); });
the error showed when "node app" ran:
luis@luis-laptop ~/www/express2 $ node app /home/luis/www/express2/node_modules/connect-redis/lib/connect-redis.js:96 redisstore.prototype.__proto__ = store.prototype; ^ typeerror: cannot read property 'prototype' of undefined @ module.exports (/home/luis/www/express2/node_modules/connect-redis/lib/connect-redis.js:96:41) @ object.<anonymous> (/home/luis/www/express2/app.js:18:42) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16) @ node.js:902:3
what session module should use? , how can set redis?
this:
var redisstore = require('connect-redis')(express);
should be:
var redisstore = require('connect-redis')(session);
edit: need npm install cookie-parser
, include var cookieparser = require('cookie-parser');
@ top , app.use(cookieparser());
right before app.use(session({ ... }));
Comments
Post a Comment