I’m considering using session in my node.js application.
I understand the following: - session-cookie use cookie to save session data on the client side - express-session use cookie to store a sessionID and all the session data are stored on the server side
I’m worried about security so I would choose express-session. But the Documentation say that by default express-session store data in memory and this not envisageable in production.
So my questions are: How do you implement session in your application? Do session stores are not influencing performance? If not, which session store would you recommend me? (my application is using MySql as database)
Thank you very much for your help. Regards.
The easiest way I found to manage session data is tokens.
You can easily use 'passport' for expressjs and nodejs.
You can generate a token that is signed in your NodeJS backend with a private key and identifiable by the public key. These tokens can even be revoked.
They are passed into the 'authorization' header as a web standard.
Here is an example of validation I use for extracting and checking a generated token a user has provided.
And here is my REST API call for a user attempting to login: (that generates a valid token)