req.user after restart node

I've attached passportjs to authenticate user on my site. I use localStrategy and all works fine. But I have some problem (may be it's feature of passportjs) - after restart node, req.user is undefined and users should login again.

What should I do to initialize req.user on start server??

You need to store user login info in Redis for e.g. because after restart, all your variables that you set will be undefined

LocalStrategy stores user credentials in memory after login. This means that when you restart node, the credentials will inevitably be lost.

However, passport does use the session cookie functionality in express, so you can persist cookies in the standard express way.

This is quite easy using the RedisStore module, to which you pass the express object:

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

Before you set up passport, enable session persistence to redis in express:

app.use(express.cookieParser());
app.use(express.session({ 
  secret: "a-secret-token", 
  store : new RedisStore({ 
    host : 'redis-hostname', 
    port : 'redis-port', 
    user : 'redis-username', 
    pass : 'redis-password' 
  }),
  cookie : {
    maxAge : 604800 // one week
  }
}));
app.use(passport.initialize());
app.use(passport.session());

You'll need to install redis on your machine, and change the details above to match the redis instance you want to connect to.