I made a small app using node.js and Heroku, set the local .env
file and also used heroku config:set VARNAME=varValue
to define the port it should listen to both locally and remotely.
PROD_MONGODB=mongodb://xxxxxxxxx@dxxxxxxxx:12345/server
PORT=3000
I've also checked the app's dashboard on Heroku and I can confirm the vars are set correctly.
Here's the server startup code using restify.
app.listen(process.env.PORT, function() {
console.log('Server listening on port number', process.env.PORT);
});
If I run the app locally using heroku local
, it runs on port 3000 as I expected:
Orion:.......$ heroku local
forego | starting web.1 on port 3000
web.1 |
web.1 | Server listening on port number 3000
But when I deploy the app on Heroku, I uses a seemingly random port:
2015-09-28T15:15:51.400324+00:00 app[web.1]: Server listening on port number 56680
2015-09-28T15:15:51.486396+00:00 heroku[web.1]: State changed from starting to up
Is there anything else I can do to make sure Heroku uses the port I defined as an environment variable?