【问题标题】:express.js trouble with connect modulesexpress.js 连接模块的问题
【发布时间】:2012-07-24 13:01:31
【问题描述】:

我无法使用 express.js 子模块,并且我认为我缺少一些与 npm 相比基本的东西。我正在尝试关注this tutorial 来构建一个简单的身份验证系统。

在应用程序目录中表示的路径:

./node_modules/express/lib/express.js

我的应用:

var express = require('express');
var app = express.createServer();
app.use(express.bodyDecoder()); // problems happen here

接下来会发生什么:

meeeeee$ node app.js 

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object #<Object> has no method 'bodyDecoder'
    at Object.<anonymous> (/Users/nflacco/Projects/santorinillc/js/auth-demo/app.js:3:17)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

也供参考,我的 package.json 文件:

{
    "name" : "my dirty little app",
    "version" : "0.0.1",
    "dependencies" : 
    {
        "express" : "2.5.9",
        "connect" : "1.8.7",
        "optimist" : "0.3.4"
    }
}

【问题讨论】:

    标签: node.js express connect npm


    【解决方案1】:

    本教程使用的是express 1.0.0rc4,而您使用的是2.5.9。早期版本的 express 依赖于 1.x 之前的版本 connect

    bodyDecoder()connect 1.x 中重命名为bodyParser()。将有问题的代码行更改为:

    app.use(express.bodyParser());

    您可能还想查看 1.x 到 2.x Migration Guide 以了解本教程中使用的版本与您正在开发的版本之间的任何其他差异。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 2022-06-11
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      相关资源
      最近更新 更多