Sessions in Node JS

前端 未结 10 892
北海茫月
北海茫月 2021-01-07 23:46

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

10条回答
  •  滥情空心
    2021-01-08 00:16

    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

提交回复
热议问题