Cannot set an IP address on Express JS app

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Cannot set an IP address on Express JS app



Trying to test an endpoint in express But keep getting 404 error.




var express = require("express")
var app = express()
//var http = require('http').Server(app)
app.get('/', function(req,res){

res.send('ok from end point')
})
var port = process.env.PORT|| 8080
var localhost = 'someLocalHost.med.gov'
console.log({'localhost':localhost,
'post':port})
//
app.listen(port,localhost,function(err){

if (err){
console.log('err')
}
else {
console.log('Listening')
}
})





Look up the || operator. You are doing process.env.PORT OR 8080. In other words, if process.env.PORT is set, that's the value that will be used, and 8080 will only be used if the former is not set.
– Claies
yesterday




||


process.env.PORT


8080


process.env.PORT


8080





Perhaps you need to read about how DNS works. Your server runs at an IP address and a client connects to an IP address. It is DNS that allows a client to lookup somehost.med.gov and find out the IP address that it should use to connect with.
– jfriend00
yesterday


somehost.med.gov




2 Answers
2



Localhost refers to 127.0.0.1. You can't just launch a server on any address that you want. If you're wanting to override localhost you can look into modifying your HOSTS file locally to setup an alias for localhost.


127.0.0.1


localhost


HOSTS


localhost



So I ended up http:// IP_ADDRESS:8080 and that took care of it.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS