ITeye博客

Node.js express 版本出现的几个常见问题

dou_shini8820 · 2013-08-08 17:10 · NoSQL · 编程语言 · Markdown

对着《Node.js》这本书练手,却发现现在express3里出现一些常见问题

 

 

 

1、使用connect-mongdo时,报错:Cannot read property ‘Store’ of undefined

 

 

var express = require('express');
var MongoStore = require('connect-mongo')(express),

 

 

 

 

 

**2、**使用app.use(express.router(routers)) 提示 has no method ‘router’

 

 

解决:原因可能是express 3.0后没有了router这个方法,继续使用之前的app.use(app.router),在app.js末尾加入:
routers(app);

 

 

 

 

**3、**req调用flash时报错,TypeError: Object # has no method ‘flash’

查看express的issues发现,flash在3.0+后的版本中已经不支持了。

 

**4、**使用dynamicHelpers时,app(req, res){ app.handle(req, res); } has no method ‘dynamicHelpers’

// 全局
app.locals({ foo: 'bar' });
// or
app.locals.foo = 'bar';

// 单个请求
res.locals({ foo: 'bar' });
// or
res.locals.foo = 'bar';

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。