I have a simple Node.js program running on port 3000 that receives POST requests and logs them:
const express = require('express');
const app = express();
app.post('/post', async (req, res) => {
console.log('req.body:', req.body);
console.log('req.rawHeaders:', req.rawHeaders);
});
However, whenenever I send it a POST request:
$ curl --data "param1=value1¶m2=value2" http://localhost:3000/post
The request received by the program just contains the headers and is missing the body:
$ node server.js
req.body: undefined
req.rawHeaders: [
'Host',
'localhost:3000',
'User-Agent',
'curl/7.73.0',
'Accept',
'*/*',
'Content-Length',
'27',
'Content-Type',
'application/x-www-form-urlencoded'
]
What am I doing wrong here? Why is the body of the request always undefined
?