---
title: "Node.js express 版本出现的几个常见问题"
author: "dou_shini8820"
date: "2013-08-08T17:10:58Z"
tags: []
categories: ["编程语言"]
slug: "node-js-express"
draft: false
lastmod: "2013-08-08T17:10:58Z"
id: 1922152
url: "https://doushini.iteye.com/blog/1922152"
---

对着《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';
```