PPNFilms
PPNFilms

Reputation: 65

"Can't POST w/ nodejs

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:

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

Answers (1)

Rahul Pal
Rahul Pal

Reputation: 106

You must note here these two points:

  • 127.0.0.1 is the loopback address (also known as localhost).
  • 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder).

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

Related Questions