Why does the call to node.js body-parser fail despite the fact that I have installed it?

As Kevin B stated, you have to install body-parser locally and save it to the manifest:

npm install --save body-parser

This answer is much simpler. Go to the base directory and link to the required global modules.

npm link body-parser

There's no need to install modules all over the place. If the module is not installed globally, the above command will install the module globally then link to it locally.


I think I was doing something fundamentally wrong - I went back to basics and started all over again, this time making sure I had a package.json file. Now it works.

Here is the code:

var express = require('express');
var session = require('cookie-session');
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var jsonParser = bodyParser.json();

var app = express();


// JSON testing
app.post('/json-test', jsonParser, function(req, res) {
    if (!req.body) return res.sendStatus(400);
    console.log(JSON.stringify(req.body));
    console.log(req.body.title);
    res.status(200).send(req.body.title);
    })

// Can't get anything else
.use(function(req, res, next){
    res.setHeader('Content-Type', 'text/plain');
    res.status(404).send('Page introuvable !');
    })


.listen(8090);

And here is the package.json

{
"name": "todo1",
"version": "0.1.0",
"dependencies": {
    "express": "~4.11.0",
    "ejs": "~2.1.4",
    "cookie-session": "~1.1.0",
    "body-parser": "~1.10.1"
},
"author": "Martin",
"description": "Un gestionnaire de todolist ultra basique"
}