Skip to content
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

Proposed check for port already in use #1569

Closed
rkulla opened this issue Apr 3, 2013 · 4 comments
Closed

Proposed check for port already in use #1569

rkulla opened this issue Apr 3, 2013 · 4 comments

Comments

@rkulla
Copy link

rkulla commented Apr 3, 2013

When express.js generates app.js to start the Express server on a port (default 3000), it throws an exception if the port is already in use. So instead, the error could be caught with the following check and produce a more descriptive error message, by changing:

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

to:

server = http.createServer(app);
server.once('error', function(err) {
  if (err.code == 'EADDRINUSE') {
    console.log(err.code + ': ' + app.get('port') + ' already in use');
  }
});
server.listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
@tj
Copy link
Member

tj commented Apr 13, 2013

EADDRINUSE is pretty descriptive IMO, even if it's just an all caps errno, any changes to make things more descriptive should be in node core, I'd love to actually patch node to display things like EADDRINUSE: http://localhost:3000 is already in use, when you have a lot of services running it can get pretty difficult to see what failed

@tj tj closed this as completed Apr 13, 2013
@tj
Copy link
Member

tj commented Apr 13, 2013

@isaacs do you think it would be reasonable to add something like ^ that in core? similar to the original patches to show the filename of file related errors I think this would help quite a bit

@isaacs
Copy link
Contributor

isaacs commented Apr 13, 2013

Yeah, we could add something helpful there, like the port/host/path you passed to listen(). Patch welcome.

@tj
Copy link
Member

tj commented Apr 13, 2013

@isaacs cool thanks for the confirmation I'll send a patch when I have a minute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants