node.js - 什么时候应该将 cookie-parser 与 express-session 一起使用?

标签 node.js session cookies express session-cookies

在大多数 ExpressJs 示例中,我发现使用 cookie-parserexpress-session

如果我可以在没有它的情况下使用 req.session.name 访问 session 数据,在什么情况下(或好处)我应该使用 cookie-parser

最佳答案

对于 future 不起眼的编码人员,他们会偶然发现这一点 - 我发布了一个最新的答案:

正如 express-session 中间件的官方描述在这里所说:express-session

Since version 1.5.0, the cookie-parser middleware no longer needs to be used for this module to work. This module now directly reads and writes cookies on req/res. Using cookie-parser may result in issues if the secret is not the same between this module and cookie-parser.

因此,只需使用 express-session 中间件,祝您有美好的一天。

关于node.js - 什么时候应该将 cookie-parser 与 express-session 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27961320/

相关文章:

Angular:如何解决SameSite Cookie问题

node.js - Bluebird.js : How to add wait for each iteration of Promise. map ?

node.js - 使用 nodemailer 通过 Node.js 发送电子邮件不起作用

java - 如何通过 Spring 在 Hibernate 中使用 ThreadLocal

mysql - 使用 session ID 过滤数据

session - Gorilla Sessions - 如何根据请求自动更新 Cookie 过期时间?

python - Django: session 在 Heroku 上没有按预期工作

javascript - 如何在 NodeJS 中传递命令行参数?

javascript - 确定 Node 流是否处于 objectMode

java - org.hibernate.exception.GenericJDBCException : Cannot open connection