Notes on deploying a MongoDB-backed Express app to Heroku

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

  1. Navigate to the directory containing your repository.
  2. $ heroku create – this creates the application on Heroku, and also adds a remote called heroku.
  3. 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.
  4. $ heroku addons:add mongolab

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.

About Jennifer Phillips Campbell

Software Developer and Medieval Historian
This entry was posted in Node.js, Version Control. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s