DEV Community

Cover image for Hosting an Application on Heroku in 7 Steps
Connor Dillon
Connor Dillon

Posted on

Hosting an Application on Heroku in 7 Steps

Before we start, go to Heroku.com and log in or sign up for an account (if you don't already have one).

You will also need the Heroku CLI tool, available from Heroku Dev Center

Heroku uses Git for source control, so make sure you have that installed as well. Git install documentation can be found here.

  1. Check that everything is installed
$ heroku -v
$ git -v
Enter fullscreen mode Exit fullscreen mode
  1. Log in through the terminal within your project directory
$ heroku login
# Then enter your email and password for Heroku
Enter fullscreen mode Exit fullscreen mode
  1. Initalize a git repository

Make sure to create a .gitignore containing anything that you don't want pushed to Heroku: node_modules, reference docs, sandbox files, etc.

$ git init
$ git add .
$ git commit -m 'Initial commit'
Enter fullscreen mode Exit fullscreen mode
  1. Initialize the Heroku container
$ heroku create
Enter fullscreen mode Exit fullscreen mode
  1. Set Heroku as Remote Repository

Go to your Heroku dashboard and open up the new Heroku container.

Scroll down to "Create a new Git repository" and grab the command to add this container as our remote repository:

$ heroku git:remote -a CONTAINER-NAME-12345
Enter fullscreen mode Exit fullscreen mode

And then paste that command into your project directory terminal.

  1. Push to master branch of Heroku App
git push heroku master
Enter fullscreen mode Exit fullscreen mode
  1. View Your New Application

Go to the URL provided when pushing to master or just type heroku open into the project terminal.

A Few Notes:

  1. In index.js, we've set const PORT = process.env.PORT || 5000 - Heroku will be using process.env.PORT and not PORT = 5000.
  2. Make sure that you have a start script in package.json - "start": "node index". Change index to whatever entrypoint you're using if necessary.

Top comments (0)