node.js - 类型错误 : express is not a function

标签 node.js express

您好,我正在尝试同时使用 jadeexpress。但它给我 TypeError。 我创建了 npm initnpm install express -save,然后是 node app.js。但它给了我同样的错误 "TypeError: express is not a function"

// Module dependencies
var express = require('express')
  , nib = require('nib')
  , mysql = require('mysql')

 var app = express();

var app = module.exports = app.createServer();


app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.logger('dev'))

package.json:

{
  "name": "reddit-node-mysql",
  "description": "A demo of how to use Express and MySQL together",
  "author": "Clarence Leung <github@clarle>",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "^2.5.11",
    "mysql": "~2.0",
    "nib": "^1.1.2",
    "jade": "^1.0.4"
  },
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "devDependencies": {}
}

解决方案 我的模块版本已过时,因此无法正确安装。我更新了它们的版本,现在可以使用了。

最佳答案

您使用的是过时的 express ,

移除
"express": "^2.5.11", 来自包 json 并运行

npm install --save express

关于node.js - 类型错误 : express is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47328825/

相关文章:

node.js - Node 快速 session 不工作。为下一个请求获取未定义的 req.session.user

angularjs - 如何获取从 Angular 到 NodeJS/Express JS 的多个 GET 请求参数

javascript - Express4 和 Passport : Unable to authenticate

node.js - NodeJS 中未确认电子邮件时自动删除 Mongo 文档

javascript - 处理快速异步中间件中的错误

node.js - nodejs mongo,生成测试数据

node.js - 从 fetchMessage 中删除用户 react ? - 不和谐JS

node.js - 在 Passport.js 和 Express 路由器中使用 next

javascript - 在一页上呈现两个 Mongo 查询的结果

node.js - 使用node/express捕获所有http请求