All writing
May 19, 2021 · 1 min read
Hosting your Express.js backend on Heroku
Step-by-step guide to deploying an Express.js backend to Heroku using the CLI, including how to push only the backend folder from a monorepo.
#express#hosting#backend
You have created an app in React Native and written backend in Express.js / Node.js and you want to host your backend so you can GET or POST data on your app from anywhere?
Answer: Heroku.
Here's how:
- Create a Heroku account on Heroku.
- Install the Heroku CLI.
# for mac:
brew tap heroku/brew && brew install heroku
# for ubuntu:
sudo snap install --classic heroku- After the Heroku CLI has been installed, open the terminal and log in with your credentials:
heroku login- Create a Heroku app:
heroku create-
Once the Heroku app has been created you will see the app name, remote git link, and the site URL.
-
Add the Heroku remote branch:
heroku git:remote -a your-app-name
# verify with
git remote -v- Add a
Procfileto the root of your backend folder. TheProcfiletells Heroku to runnode app.json its server so your app can start.
You don't need to push the whole repo — push only the backend folder:
git subtree push --prefix MainBackendFolder heroku masterAfter build, Heroku will give you a URL — point your app's API calls at it.