How to Deploy Node Express API to Heroku

JonathanSanchez.Dev
2 min readAug 8, 2022

--

So you’ve built an awesome API using Express with Node.js and now you want it to be public for any service or web application to use.

I’ve found that Heroku is one of the easiest and fastest way to deploy the API to the cloud

Prerequisites:

For MAC users

  1. Have a free Heroku account — https://signup.heroku.com/
  2. Node and NPM installed on your mac, if you don’t have them installed checkout this article
  3. Have the Heroku CLI tools installed with brew (if you don’t have brew ):
brew tap heroku/brew && brew install heroku

Steps Breakdown

  1. Create local Node Express API (using your terminal, if you don’t have an API already)
    a. Create a project working directory or folder -
    $ mkdir node-express-api-heroku
    b. Go into the new project folder $ cd node-express-api-heroku
    c. Initialize this folder as a Node project $ npm init -y
    d. Create files index.js, .gitignore files $ touch index.js .gitignore
    c. Install Express and Cors with $ npm install express cors

2. Add configurations to package.json

Notice: the start script, the engines the to specify the version of node

3. Add your routes and configurations on index.js

Configure a simple NODE Express Api

4. Initialize Git, stage files, commit your changes and change branch name to main

$ git init 
$ git add .
$ git commit -m 'first commit message'
$ git branch -M main

5. Connect your Heroku account to your machine

$ heroku login

Use heroku login this will open a browser and will authenticate with Heroku

6. Create Heroku Instance

$ heroku create

7. Push your Node Express API to Heroku

$ git push heroku main

8. Visit your Heroku instance with a public link provided by Heroku

It could be something random like:

https://fast-woodland-77884.herokuapp.com/

Enjoy!!!! 🎉

Leave some comments and or question if you get stuck, would love to read your feedback 😎

Sources:

https://medium.com/geekculture/deploy-node-applications-on-heroku-a89ed51e0a34

--

--

JonathanSanchez.Dev

Developer by day, rockin' drummer by night. Loves dogs🐶 and collaborating with fellow engineers. Passionate, creative, and always up for a coding adventure! 🚀