1
var express=require('express')
var app=express();

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

app.use(express.urlencoded());

The above code throws the following error :

[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

Seems like a similar question here - express.js trouble with connect modules but I'm already having express3.0.0 checked using the suggestion listed here - Find the version of an installed npm package

I also read the Api docs here - http://expressjs.com/api.html and they list urlencoded()

Please help.

I would also like to point, that I also tried using bodyParser() but that too gave the same error of has no method

Community
  • 1
  • 1
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • Coding_idiot provides a solution. Or you can still use Express 3.4.8: `npm install express@3.4.8`. – bnuhero Mar 06 '14 at 00:35

1 Answers1

7

The express guide is a bit-outdated.

For others having the same problem, the solution is that those methods have moved to a new module body-parser

Sample Code

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

app.use(bodyParser.urlencoded());
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • Thank you. My production server updated to a newer version and I was REALLY scratching my head on this one. – Yablargo Jun 02 '14 at 01:27