I thought you were going to Heroku. Heroku assigns a random port to the application environment. You can take this random port to your code, like this one.
process.env.PORT
My sample code that I used is here:
// production
config.port = process.env.PORT
app.listen(config.port, () => {
logger.info('Listening on port %d', config.port);
});