How to get cookie value in expressjs

后端 未结 3 1722
轮回少年
轮回少年 2020-12-09 08:46

I\'m using cookie-parser, all the tutorial talk about how to set cookie and the time it expiries but no where teach us how to get the value of these cookie

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 09:27

    For people that stumble across this question, this is how I did it:

    You need to install the express cookie-parser middleware as it's no longer packaged with express.

    npm install --save cookie-parser
    

    Then set it up as such:

    const cookieParser = require("cookie-parser");
    
    const app = express();
    app.use(cookieParser());
    

    Then you can access the cookies from

    req.cookies
    

    Hope that help.

提交回复
热议问题