【问题标题】:node express module throwing 'has no method urlencoded' error节点快递模块抛出“没有方法 urlencoded”错误
【发布时间】:2014-04-08 04:44:47
【问题描述】:
var express=require('express')
var app=express();

console.log("Encoded ",express.urlencoded());

app.use(express.urlencoded());

上面的代码抛出以下错误:

[user@localhost nodejs]$ node program.js

/home/user/Desktop/nodejs/program.js:41
console.log("Encoded ",express.urlencoded());
                               ^
TypeError: Object function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, proto);
  mixin(app, EventEmitter.prototype);

  app.request = { __proto__: req, app: app };
  app.response = { __proto__: res, app: app };
  app.init();
  return app;
} has no method 'urlencoded'
    at Object.<anonymous> (/home/user/Desktop/nodejs/program.js:41:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

这里似乎是一个类似的问题 - express.js trouble with connect modules 但我已经使用此处列出的建议检查了 express3.0.0 - Find the version of an installed npm package

我还在这里阅读了 Api 文档 - http://expressjs.com/api.html,他们列出了 urlencoded()

请帮忙。

我还想指出,我也尝试使用bodyParser(),但这也给出了与has no method相同的错误

【问题讨论】:

  • Coding_idiot 提供了一个解决方案。或者您仍然可以使用 Express 3.4.8:npm install express@3.4.8

标签: node.js express


【解决方案1】:

快速指南有点过时了。

对于其他遇到相同问题的人,解决方案是这些方法已移至新模块body-parser

示例代码

var express=require('express');
var app=express();
var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded());

【讨论】:

  • 谢谢。我的生产服务器更新到了新版本,我真的在这个问题上摸不着头脑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-12
  • 2013-07-11
  • 2017-06-20
  • 2016-02-26
  • 1970-01-01
  • 2015-03-09
相关资源
最近更新 更多