'Postman Express.js Response Body is always empty
I have been stuck on this problem for a day. I cannot solve.
I have a VERY simple node app.
const express = require("express");
const port = 3001;
const app = express();
app.use(express.json());
app.post('/', (req, res, next) => {
console.log("Body: ", req.body);
res.json(req.body);
})
app.listen(port);
console.log(`Serving at http://localhost:${port}`);
If I run this in a browser using any code extracted from Postman - it returns the expected result:
Body: { test: 'defrejbar',
email: '[email protected]',
password: '43747638bar' }
However, if I run the EXACT same function directly from Postman, I receive an empty response.
I have tried adding body-parser, however that did not work. The only solution I have, would be to resort to Param Queries (which work), however I would prefer to be running with Response Body.
Any help would be greatly appreciated.
Solution 1:[1]
@Reyno Pointed me in the right direction.
There was no issue with the code - it was a Postman issue. I'm not sure of the exact setting, but all I did was create a new Collection and added a new Request. The only difference between the 2 collections, is the old one has a heap of existing Requests - each with different endpoint.
Weird... but it worked. Hope it helps someone else out there with the same issue.
Solution 2:[2]
I also faced the same issue but when I select x-www-form-urlencoded of postman it displays my response body.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JJ Setsta |
| Solution 2 | Tyler2P |

