-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Mean" behavior: express does not complain if the port is undefined #3364
Comments
Hi @paulbrie the |
For reference, here is what that gives on Node.js 6.11.1:
|
Hi Doug, I'm on Mac Sierra.
Here's the end of my main file:
The output in the console:
|
Hm, I'm not sure. Regardless, the Does the following app have an error on Node.js 7.9.0 ? It does on 6.11.1, at least. If it doesn't, looks like maybe a regression you need to report to Node.js folks :) var http = require('http')
var app = function () {}
var server = http.createServer(app)
server.listen(undefined, function () {
console.log(`Server is running`)
}) And here is a one-liner:
|
Hi Doug, I like the one-liner! :) And here's the result for me:
I'll go and post this to them. |
Yep, looks like the |
You were right!
I killed the process and restarted it
A bit counter intuitive. Any interesting reason for randomising the port? |
I'm not sure. Probably a question for Node.js core folks :) |
I do believe this changed recently, but I believe that it was that it no longer accepts EDIT: Ok, just tried it with node 8 and 6. In node 6 |
As for "why" using a random port, we use it for running multiple instances of a service on one machine and then registering with a service discovery layer like Consul. So we tell all our prod services to open on any random open port picked by the OS, then send that to Consul so the other services know how to reach it. EDIT: using port 0 is a unix systems thing to tell it to pick a random tcp port. |
Hi Wesley, thanks so much for the explanation. Now it makes sense and I get why this behavior has been implemented. |
I think you have defined a variable called |
Yes, I did somewhere above an it was receiving a default value. |
In my case, process.env.PORT was not defined and
${port}
was. Therefore I was having the impression that the server was running on the port displayed into the console.It would be great if a check was done on the port parameter. Is there a specific reason why it's not?
Thanks,
Paul
The text was updated successfully, but these errors were encountered: