DEV Community

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

Posted on

2 1

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.

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay