I'm trying to write a stupidly simple Hello World program in Express that outputs some basic data about the current HTTP request.
For POST requests, I'd like to see the raw POST body.
const express = require('express');
const app = express();
function handleRequest(req, res) {
console.log('\n-- INCOMING REQUEST AT ' + new Date().toISOString());
console.log(req.method + ' ' + req.url);
console.log(req.body);
res.send('Hello World!');
}
app.all('/*', (req, res) => handleRequest(req, res));
app.listen(3000, () => console.log('Example app listening on port 3000!'));
When I fire off any type of POST request from Postman, req.body
is set to undefined
. Why is req.body
empty? How can I print out the raw POST data? I don't need a parsed version of the POST body, just the raw data.