新手 请教“TypeError: express is not a function” .

我是新手,在网上看到一个node.js的教程,初始化一个项目,跟着教程打下来,代码启动总是提示错误:

D:
odejscmsapp.js:3
var app = express; ^ TypeError: express is not a function at Object.<anonymous> D:
odejscmsapp.js:3:11 at Module._compile module.js:410:26 at Object.Module._extensions..js module.js:417:10 at Module.load module.js:344:32 at Function.Module._load module.js:301:12 at Module.require module.js:354:17 at require internal/module.js:12:17 at Object.<anonymous> D:
odejscmsinwww:3:11 at Module._compile module.js:410:26 at Object.Module._extensions..js module.js:417:10 

app.js代码如下:

var express = require./config/express;
var app = express;
module.exports = app;

/config/express.js代码如下:

var express = requireexpress;
var bodyParser = requirebody-parser;
module.express = function{ console.loginit express...; var app = express; app.usebodyParser.json; app.usefunctionreq, res, next{ res.status404; try { return res.jsonNot found; } catche { console.error404 set header after sent; } }; return app;
}; 

bin/www代码如下:

#!/usr/bin/env node
var app = require../app;
var config = require../config/config;
app.listenconfig.port, function{ console.logapp started, listening on port: + config.port;
};

package.json :

{ "name": "cms", "version": "1.0.0", "description": "demo app", "main": "bin/www", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "abc", "license": "ISC", "dependencies": { "body-parser": "^1.15.0", "express": "^4.13.4" }
}

请麻烦帮忙看一下, 谢谢。

config/express.js 中

module.express

改成

module.exports

发表评论

电子邮件地址不会被公开。 必填项已用*标注