【node】关于Most middleware (like session) is no longer bundled with Express and must be installed ……
来源:互联网 发布:Mac pro 怎么看芒果TV 编辑:程序博客网 时间:2024/05/17 20:57
今天在实现mongodb数据库的过程中,遇到一个如题这个问题,这个问题的意思是:大多数中间件(像session)不再随express一起安装。
在express 4.0之前的版本,像session之类的中间件是伴随express自动安装的,网上有的教程使用的express版本正是4.0之前的版本,所以在使用4.0及其之后版本的时候一定要注意这点。
我的代码中使用session中间件的代码:
app.use(express.session({secret:setting.cookieSecret,key:setting.db,cookie:{maxAge:1000*60*60*24*30},store:new MongoStore({db:setting.db})}));
这是在实现mongodb回话组建connect-mongo时需要的。
查看node_modules\connect-mongo\Readme.md可以看到4.0之后的用法已经不一样了。内容:
With express4: var session = require('express-session'); var MongoStore = require('connect-mongo')(session); app.use(session({ secret: settings.cookie_secret, store: new MongoStore({ db : settings.db, }) }));With express<4: var express = require('express'); var MongoStore = require('connect-mongo')(express); app.use(express.session({ secret: settings.cookie_secret, store: new MongoStore({ db: settings.db }) }));With connect: var connect = require('connect'); var MongoStore = require('connect-mongo')(connect);
【解决办法】:
在package.json中加入express-session的中间件,命令提示符进入项目目录下,npm install 重新安装。或是在目录下使用命令安装:npm i express-session即可将express-session安装到项目中。在使用的模块中加入
var session = require('express-session'); var MongoStore = require('connect-mongo')(session);
……
使用的时候不在使用express.session,而是直接使用session():
app.use(session({secret:setting.cookieSecret,key:setting.db,cookie:{maxAge:1000*60*60*24*30},store:new MongoStore({db:setting.db})}));
0 0
- 【node】关于Most middleware (like session) is no longer bundled with Express and must be installed ……
- node Error: Most middleware (like session) is no longer bundled with Express and must be installed
- Most middleware (like bodyParser) is no longer bundled with Express
- Tomcat's administration web application is no longer installed by default. Download and install the
- Error: Most middleware (like bodyParser) ...
- 关于ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc
- ication is no longer installed by default. D(Tomcat没有管理员界面)
- 如何解决TOMCAT的Tomcat's administration web application is no longer installed by default
- 解决TOMCAT的 administration web application is no longer installed by default问题
- (转载)如何解决TOMCAT的Tomcat's administration web application is no longer installed by default
- node+express+http-proxy-middleware代理转发
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- Debugger is no longer active
- Jobs added with no trigger must be durable
- Jobs added with no trigger must be durable
- his bundle is invalid . new apps and app updates submitted to the app store must be built with publi
- this bundle is invalid . new apps and app updates submitted to the app store must be built with publ
- Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.
- Servlet在web.xml中的配置
- 如何在Struts的Action中直接使用POI生成Excel并下载
- Unity3D教程游戏开发鼠标路线
- Linux 下IPC总结(全)
- 分布式搜索elasticsearch java API 之(八)------使用More like this实现基于内容的推荐
- 【node】关于Most middleware (like session) is no longer bundled with Express and must be installed ……
- OCP-1Z0-051-题目解析-第11题
- button的长按事件
- unable to connect to your virtual device genymotion will now stop check your virtualbox network
- code review
- 关注C++细节——含有本类对象指针的类的构造函数、析构函数、拷贝构造函数、赋值运算符的例子
- svn http支持
- 给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点
- 基于安卓的课程设计——加速度检测应用