提问者:小点点

node express模块引发“Has no method UrlenCoded


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问题,但是我已经使用这里列出的建议检查了express3.0.0--查找已安装的npm包的版本

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

请帮帮我。

我还想指出,我也尝试使用BodyParser(),但也给出了同样的错误Have no method


共1个答案

匿名用户

快递指南有点过时了。

对于其他有相同问题的方法,解决方案是将这些方法移到一个新模块body-parser

示例代码

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

app.use(bodyParser.urlencoded());