Reference: Getting Started with Node.js on Heroku
Preparing your application for deployment
Use the configured port
Reference: Gotchas for Node JS apps on Heroku
Make sure it listens on the port defined in process.env.PORT
. If it’s set to listen on some other port, when you try to access it via a browser you’ll see a message about an error occurring in your application and the logs will show something like:
...
2015-04-06T14:30:19.163763+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" ...
2015-04-06T14:30:34.754286+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Webprocess failed to bind to $PORT within 60 seconds of launch
2015-04-06T14:30:34.754371+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-04-06T14:30:35.842405+00:00 heroku[web.1]: State changed from starting to crashed
2015-04-06T14:30:35.832461+00:00 heroku[web.1]: Process exited with status 137
Use the configured MongoDB connection string
Reference: Deploying a MEAN stack app to Heroku
When you add the MongoLab add-on Heroku will put the connection string in process.env.MONGOLAB_URI
, so you need to make sure you are using this value when making the connection.
Setting up the Heroku application and database
Reference: Deploying with Git, MongoLab
- Navigate to the directory containing your repository.
$ heroku create
– this creates the application on Heroku, and also adds a remote calledheroku
.- If you have not verified your Heroku account by adding credit card details, you will need to do so to be able to add MongoLab.
$ heroku addons:add mongolab
Deploying
Reference: How can I deploy from a Git subdirectory?
I had my AngularJS front-end and the Express back-end in the same repository. Heroku expects the app directory to be in the root of the repository (Deploying with Git), so I needed to be able to push a subdirectory to my heroku
remote. This is possible using git-subtree:
$ git subtree push --prefix my-subfolder heroku master
Note: I got an error message when I tried to run this from the normal Windows command line on my machine, but it worked in Git Bash.