Express 4.0 and up:
$ npm install --save body-parser
And then in your node application:
const bodyParser = require('body-parser'); app.use(bodyParser);
Express 3.0 and below:
Try passing this in your cURL call:
--header "Content-Type: application/json"
and make sure your data is in JSON format:
{"user":"someone"}
Alternatively, you can use console.dir in your node.js code to see the data inside the object, as in the following example:
var express = require('express'); var app = express.createServer(); app.use(express.bodyParser()); app.post('/', function(req, res){ console.dir(req.body); res.send("test"); }); app.listen(3000);
This other question may also help: How to get JSON in a node.js POST express request?
If you do not want to use bodyParser, check this other question: https://stackoverflow.com/a/167295
Hector Correa Jul 24 2018-12-12T00: 00Z
source share