Sessions in Node JS

前端 未结 10 805
北海茫月
北海茫月 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:14

    Follow below steps:

    1. npm install express-session --save
    2. Write below code:
        var express = require('express');
        var session = require('express-session');
        var app = express();
        app.use(session({secret: 'your secret key', saveUninitialized: true, resave: true}));
        var userId = 1234;
        app.get('/', function (req, res, next) {
            req.session.userId = userId;
        }); 
    

提交回复
热议问题