Reputation: 980
I'm trying to use express session 'connect-redis' for first time. Here is my code:
var express = require('express');
var app = express();
var RedisStore = require('connect-redis')(express);
app.use(express.cookieParser());
app.use(express.session({ store: new RedisStore, secret: 'lolcat' }));
app.get('/logging', function(req, res) {
if (req.session.logged) {
res.send('Welcome back!');
} else {
req.session.logged = true;
res.send('Welcome!');
}
});
app.listen(8888);
When I try to start the server through command line, it shows error:
RadisStore.prototype._proto_= Store.prototype;
TypeError: Cannor read property 'prototype' of undefined;
That is 'Store' is undefined. What is the wrong with my code?
Upvotes: 0
Views: 3087
Reputation: 9938
You forgot the parenthesis:
app.use(express.session({ store: new RedisStore(), secret: 'lolcat' }));
First. But secondly, you need to add options (https://github.com/visionmedia/connect-redis):
app.use(session({ store: new RedisStore({
client: An existing redis client object you normally get from redis.createClient(),
host: Redis server hostname,
port: Redis server portno,
ttl: Redis session TTL in seconds,
db: Database index to use,
pass: Password for Redis authentication,
prefix: Key prefix defaulting to "sess:",
url: String that contains connection information in a single url (redis://user:pass@host:port/db),
}), secret: 'keyboard cat' }))
Upvotes: 1