我正在学习connect的内置中间件,使用cookieParser时,报“has no method”错误, connect包我有引入的,请问大家怎么解决呀? 以下是我的代码。
var connect = require("../node_modules/connect");
var app = connect();
app
.use(connect.cookieParser('tobi is a cool ferret'))
.use(function(req, res){
console.log(req.cookies);
console.log(req.signedCookies);
res.end('hello\n');
}).listen(3000);
4 回复
问题解决。通过npm找到connect的github 找到这样一段话:“All node patches will be removed - all middleware should work without Connect and with similar frameworks like restify” 原本connect的内置中间件被分离出来,不依赖connect也能够work。 要使用cookieParser组件,还需cmd运行 npm install cookie-parser
@EdmondWang npm install connect; npm install cookie-parser; 这样是不是 找不到路径呀,还是 报 has no method ‘cookieParser’