Deploy your app with Heroku

effingkay profile image Klaudia Updated on ・3 min read

I am not deploying my apps very often (they usually end up almost finished somewhere in my local hell), so every time I find myself with the task to do so, the fairly simple process turns into the research and remembering commands I used in my previous lives. Hence, this guide.

I will show the process of deploying an Express app using MongoDB with Heroku step by step.


First, to deploy an app, you will need an app. I have one fairly simple REST API on my github already which we can use for this tutorial. You can find it here. Simply fork it and make local copy so we can make changes to it later.

To use Heroku, you will need git and heroku. I'm assuming we all have git on our machines so the next step is to install heroku CLI if you don't already have it. On Mac machines, simplest way is to install it with brew (for different OS refer to heroku docs )

brew install heroku/brew/heroku

You will also need to create an account at Heroku website (free for up to 5 apps).

Prepare your repo

Now, if you have a copy of the repo, we need to create Procfile. Procfile is a heroku specific file where you define commands that will run on your dyno. It should be called Procfile (no file extention) and should be localted in your root directory. I usually add one command to my file, using forever package which basically restart your app in case it crashes. Simply run these commands in the root directory of your app:

> npm i forever --save
> touch Procfile

Now, we need to add this to your Procfile.

web: ./node_modules/.bin/forever -m 5 index.js

Commit all your changes before moving on to the next step.

Create heroku app

Heroku docs explain this process quite well and if you find any issues, I would recommend referencing them. But to put it simply, run the following command in your terminal.

> heroku create

Creating app... done, ⬢ afternoon-dawn-70065
https://afternoon-dawn-70065.herokuapp.com/ | https://git.heroku.com/afternoon-dawn-70065.git

> git push heroku master

This created the app and assigned it a name and URL, however, we still need to enable MongoDB.

Install mLab add-on

Heroku offers free add-on for MongoDB and it's fairly easy to implement to your app.

In index.js and also in db/seeds.js, we need to add MONGODB_URI to mongoose connect function, so I changed it to look like this:

mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/polling');

Also in index.js change the port declaration on the last line to:

app.listen(process.env.PORT || 3000, () => console.log('Server has started'));

Commit your changes and push them to heroku ( git push heroku master ), then we can add mongolab with this command:

> heroku addons:create mongolab

Creating mongolab on ⬢ afternoon-dawn-70065... free
Welcome to mLab.  Your new subscription is being created and will be available shortly.  Please consult the mLab Add-on Admin UI to check on its progress.
Created mongolab-deep-94113 as MONGODB_URI
Use heroku addons:docs mongolab to view documentation

Populate your database

I created the seeds.js file which populates your database with dummy data. You can run it and populate your Heroku database like this:

> heroku run node db/seeds.js 

collections dropped
... some not important warnings, bla bla
Candidates created.
Users created.

And now, if you go to https://your-app-name.herokuapp.com/api/users or https://your-app-name.herokuapp.com/api/candidates you should get a response (JSON with user and candidates info).

So yeah, it is as simple as that to deploy your app, it's just harder if it's your first time or if you haven't done it in a year or so. Thank you for reading!

Posted on by:


Editor guide

Longtime happy Heroku user here. Nice writeup.


Thank you! Glad you liked it


I love the simplicity of Heroku.

But find the cost spikes high outside of the simplest applications.

Even for minor MVPs it just becomes too costly for things that are bootstrapped financially.

And then for larger projects, it gets even crazier unless your pockets are deep and no one is paying attention.


I see your point and agree, Heroku can get pretty expensive pretty fast, however, I think it's a great tool for beginners who want to deploy their apps, to showcase in their portfolio for example. I remember I had all my apps there when I started with coding and never had any problem with the cost. Even now, for a simple API, Heroku is my first choice.


Yup, my entire portfolio (including my portfolio site itself) is on Heroku.


"(...) they usually end up almost finished somewhere in my local hell (...)" Yeah, mine too. 😁

Great writeup. 👏


Heh, I'm glad I'm not the only one who abandons my apps!

And thank you!