connect-redis and express-session results in req.session undefined
You probably have some connection errors, but connect-redis
does not output them to console (see connect-redis source code). To see them you can create a separate module that creates a client instance and pass it to RedisStore
constructor:
// redisClient.jsvar redis = require('redis');var redisClient = redis.createClient('localhost', 6379); // replace with your configredisClient.on('error', function(err) { console.log('Redis error: ' + err);}); module.exports = redisClient;
Redis client emits also other event that may be helpful in debugging - see node-redis docs
// your codevar redisClient = require('./redisClient.js`);(...)app.use(session({ store: new RedisStore({ client: redisClient }), secret: config.secret, saveUninitialized: true, resave: false }));