How can I maintain my SESSIONS in Node JS ? E.g I want to store UserID in SESSION using Node Js. How can I do that in Node JS ? And can I use that Node JS SESSION in PHP too
You don't need to to it by yourself. There are some amazing modules in nodeJS that handle this kind of things for you.
You can use session middleware from express, as suggested before.
However, I'd recommend you to use passportJS. This module does the authentication part for you, has a lot of strategies that you could integrate in your website (login with facebook, google, twitter, etc etc), and deals with all the session stuff automatically, using serializeUser()
and deserializeUser()
functions whenever you need to.
You can take a look at this here, within session section: http://passportjs.org/docs/configure
ExpressJS has official session middleware, it is also the current de-facto standard web framework for Node.js.
If you wish to implement session support on your own, this is how the implementation is normally done, upon every request:
You will also have to implement some timeout mechanism, so that after a while the session objects are deleted, at least from memory.
You can handle the session in two-way.
I think token based session handling is more important rather than using express-session. You will get a problem when you scale your server and also a problem some single device login situation.
For Checking I have Token Based Session Hanling node js folder structure.You can check. It may be helpful
Let me divide your question in two parts.
1. How can I maintain my SESSIONS in Node JS ?
Answer: Use express-session middleware for maintaining SESSIONS
2. can I use that Node JS SESSION in PHP too ?
Answer:
Yes, you can use that session in PHP too but keep in mind you have to store that session in database.