title: bodyParser doesn't seems to work
body: <p>Sorry if this question may sounds "simple", but I can't get <code>body-parser</code> to work on this very simple example :</p>
  
  <pre><code>"use strict";
  
  const PORT = 3000;
  const express = require("express");
  const bodyParser = require("body-parser");
  const app = express();
  
  app.post("/api/login", (req, res) =&gt; {
    if (!req.body) return res.sendStatus(400);
    res.send("welcome, " + req.body.username);
  });
  
  
  app.use(express.json());
  app.use(bodyParser.json());
  
  console.log(`Listen on port ${PORT}`);
  app.listen(PORT);
  </code></pre>
  
  <p>Command line to try it :</p>
  
  <p><code>curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login
  </code></p>
  
  <p>And it always respond with 400 ! I tried a lot of configuration and didn't find a solution.</p>
  
  <p>I'm sure it's pretty simple because no one seems to have the same error, so I'm missing something but don't know what !</p>
  
  <p>express : 4.16.2</p>
  
  <p>body-parser : 1.18.2</p>
  
  <p>Thanks for your help !</p>
  
  <p><strong>EDIT</strong> : The solution was that I needed to put the middleware <strong>before</strong> the route definition. I my case, <code>body-parser</code> isn't needed I could just use <code>express.jon()</code> built in API.</p>
  
  <pre><code>"use strict";
  
  const PORT = 3000;
  const express = require("express");
  const app = express();
  
  app.use(express.json());
  
  app.post("/api/login", (req, res) =&gt; {
    if (!req.body) return res.sendStatus(400);
    res.send("welcome, " + req.body.username);
  });
  
  console.log(`Listen on port ${PORT}`);
  app.listen(PORT);
  </code></pre>