node js: Fix bodyParser error (is no longer bundled with Express)

Written by - 1 comments

Published on - last updated on April 29th 2022 - Listed in Linux Unix Rant

Let me begin with: I am no professional with node.js. Hell it's the first time I'm working on a node.js script. So you can imagine my eyebrows raising up when I saw that error when I tried to move an existing script to a newer platform:

nodejs /home/myscripts/callMe
Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see
    at Function.Object.defineProperty.get (/home/myscripts/node_modules/express/lib/express.js:89:13)
    at Object. (/home/myscripts/lib/callMe/app.js:16:17)
    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 Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object. (/home/myscripts/sbin/callMe:2:1)
    at Module._compile (module.js:456:26)

The app.js contained the following definitions at the begin:

var app = express();

According to this stackoverflow question, the "Express" module has removed the bodyParser function in newer versions. Instead of using this function as part of Express, it can now be used as its own module:

var app = express();
// Disabled because its not working anymore
// ... use body-parser package instead
var bodyParser = require('body-parser');

Just needed to install the node.js module body-parser on the system:

npm install body-parser

And then the script was working again.

Add a comment

Show form to leave a comment

Comments (newest first)

AJEESH K U from BANGALORE wrote on Mar 15th, 2016:

Hiiiii,me also new to this.
I have d same pblm,i tried many things.
But finally it works according to ur instruction.