17

I'm getting bellow warning when using NODE_ENV=production. What's the fix for this?

Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and obviously only work within a single process.

benomatis
  • 5,536
  • 7
  • 36
  • 59
Ganesh Kumar
  • 1,341
  • 11
  • 18
  • 2
    Take a look at this answer: [http://stackoverflow.com/questions/10760620/using-memorystore-in-production#10761522][1] [1]: http://stackoverflow.com/questions/10760620/using-memorystore-in-production#10761522 – Milan Babuškov May 25 '12 at 21:26

1 Answers1

8

It could be a good idea to use Redis as your session manager. It appears as though you're using either the Express or Connect framework, and for either of them you could use an npm package connect-redis (having installed Redis). With that installed the express code would look something like this:

var express = require ( 'express' )
   , RedisStore = require ( 'connect-redis' ) ( express )
   , sessionStore = new RedisStore ()
   , app = express.createServer ()
   ;

app.configure ( function () {

   app.use ( express.cookieParser () );
   app.use ( express.session ( {
    secret: "keyboard cat", store: sessionStore, key: 'hello.sid'
   } ) );
...
Bijou Trouvaille
  • 8,794
  • 4
  • 39
  • 42
  • i was used Redis for session store. but here i need just for admin authentication. That's why i'm looking for simple solution – Ganesh Kumar Mar 24 '12 at 21:18
  • 2
    @GaneshKumar this [so question](http://stackoverflow.com/questions/8749907/what-is-a-good-session-store-for-a-single-host-node-js-production-app) deals with specifically your problem. Perhaps instead of a database you may wish to explore the secure cookie route described in the question linked. – Bijou Trouvaille Mar 25 '12 at 10:11