sandaemax sandaemax - 1 month ago 9
Node.js Question

Why nodejs http request doesn't work when accessing a local served express app?

I have an express REST API app running on 8082. Then I'm trying to do a call from my another app using request:

request.post({
url: 'http://localhost:8082/test',
method: 'POST',
json: {
code: 'Hello'
}
}, (err, res, body) => {
console.log(err)
console.log(res)
console.log(body)
})


But I'm getting a
502 Bad Gateway
error:

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>


Does it look like it's looking into Nginx but not to expressjs?

How can I force it to look into my running app?

Answer

Check your other app code for the right port, or change the port if nginx is listening on that port.