Reputation: 65
I just wanna make an app.post req. with postman, but i honestly don't know what's wrong, here's the code:
const express = require('express');
const PORT = 8080;
const HOST = '0.0.0.0';
const app = express();
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
//What im trying to do:
**app.post('/test',(req, res) => {
res.status(200).send('Hello World')
});**
Here's what im doing, step by step:
npm start (At the terminal, and yes, into the project directory) The terminal displays the following:
*> node src/index.js
Running on http://0.0.0.0:8080*
Then, with Postman opened, im using the method "post" with the following link: http://0.0.0.0:8080/test
The point is, on postman im getting this as response:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /test</pre>
</body>
</html>
Instead of this:
Hello World
So...I really don't know what's wrong...
Upvotes: 0
Views: 64
Reputation: 106
You must note here these two points:
Changing HOST to 127.0.0.1 will fix the issue you are facing.
You can read more about the differences between the two right here
Upvotes: 1