学Blog实例,app.use(express.cookieParse());处报错,代码及报错信息如下,请高手指教。
发布于 2年前 作者 billy 1799 次浏览

本人初学node.js,跟着该社区前辈做这个实例

var express = require(‘express’) , routes = require(‘./routes’) , user = require(‘./routes/user’) , http = require(‘http’) , path = require(‘path’) , MongoStore=require(‘connect-mongo’) (express) , settings=require(‘./settings’) , flash=require(‘connect-flash’);

var app = express();

// all environments app.set('port’, process.env.PORT || 80); app.set('views’, __dirname + ‘/views’); app.set('view engine’, ‘ejs’); app.use(flash()); app.use(express.favicon()); app.use(express.logger(‘dev’)); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParse()); app.use(express.session({ secret:settings.cookieSecret, store:new MongoStore({ db:settings.db }) })); app.use(app.router); app.use(express.static(path.join(__dirname, ‘public’)));

// development only if (‘development’ == app.get(‘env’)) { app.use(express.errorHandler()); }

routes(app);

http.createServer(app).listen(app.get(‘port’), function(){ console.log('Express server listening on port ' + app.get(‘port’)); });

app.use(function(req,res,next){ var err=req.flash(‘error’), success=req.flash(‘success’); res.locals.user=req.session.user; res.locals.error=err.length ? err:null; res.locals.success=succcess.length ? success:null; next(); });

app.use(express.cookieParse()); ^ TypeError: Object function createApplication() { var app = connect(); utils.merge(app, proto); app.request = { proto: req }; app.response = { proto: res }; app.init(); return app; } has no method ‘cookieParse’ at Object.<anonymous> (D:\nodejs\exblog\app.js:26:17) at Module._compile (module.js:456:26) at Object.Module._extensions…js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3 [Finished in 1.7s]

5 回复

express.cookieParser(‘test’);

依然不行。 app.use(express.cookieParse(“mycookie”)); ^ TypeError: Object function createApplication() { var app = connect(); utils.merge(app, proto); app.request = { proto: req }; app.response = { proto: res }; app.init(); return app; } has no method ‘cookieParse’

app.use(express.cookieParse(‘mycookie’)); ^ TypeError: Object function createApplication() { var app = connect(); utils.merge(app, proto); app.request = { proto: req }; app.response = { proto: res }; app.init(); return app; } has no method ‘cookieParse’

你写错了吧,是express.cookieParser(), 而不是express.cookieParse啊,你少了最后那个r

确实是少了一个r,谢谢了。

回到顶部