Skip to content

Proposed check for port already in use #1569

@rkulla

Description

@rkulla

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'));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions