Before you jump into this tutorial you do need to have a few things installed first before you can start.
🚨If your goal is to combine React UI + API (Node, Ruby, Python…) into a single app, then this tutorial is not the answer.
Requirements:
- Node / NPM — Click the link and download the installer
- Git — Click the link and download the installer
- Heroku CLI — Click the link and download the installer
Steps:
- Sign up for Heroku
- Setup our React App for deployment
- Create Heroku git repository
Step 1 — Sign up For Heroku
Visit Heroku for free hosting
This step explains itself, we need to sign up for Heroku before we can do any deployment. So head over to Heroku and sign up. Once you signed up make sure you head over to your email and confirm your account.
Step 2 — Setup React App
Open up your React app (I’m using create-react-app) and open up your package.json file. If your using create-react-app we’re going to add a new object called engines. Inside of our engines object, we need to specify the versions for npm and node. To do this open up your terminal and type in:
- npm -v
Press enter
- node -v
Press enter
Your versions may be different than mine, but that's fine. Once you specified your engine versions save your file.
Step 3 — Create Heroku Git Repository
With your terminal still open navigate to your React app folder and change directory into it. Now we need to connect our project to Heroku. If you haven’t already installed the Heroku CLI. To make sure it’s installed correctly run this command:
- heroku --version
You should see your Heroku CLI version. Once that is installed we need to setup up Heroku git repository by running these commands:
- heroku login (Enter your Heroku credentials)
- git init
- git add .
- git commit -m “initial commit”
- heroku create (You should see two links after running this command. Copy the second one)
- git remote add heroku PASTE THE LINK YOU JUST COPIED
- git push heroku master
Once you run the last command Heroku will start to run some tests on your app. If everything goes right you should see a successful deploy message. Now you’re able to navigate to your app by running:
- heroku open
Anytime you make changes to your app and want to re-deploy the only commands you need to run are:
- git add .
- git commit -m “any message goes here”
- git push heroku master
Easier Method 😁
Now that I made you go through all of that process, there is an easier method if you use Github. All you have to do is log into your Heroku account; click “new” then “create new app” and give your app a name. After clicking create you should be greeted with a dashboard for the app you just created. Navigate to the deploy tab and sync your Github account with Heroku. After syncing your Github account and can search for the repository you want to sync with Heroku by scrolling down to “App connected to Github” section and searching for the repository you want to sync. You can also set up automatic deployment, so every time you push to the master branch Heroku will rebuild your app for you.
Enjoy your free hosting!
Follow me on social media:
Twitter
Instagram | Personal
Instagram | Developer
Linkedin
Youtube

Latest comments (22)
Everytime I have getting this error -
heroku : The term 'heroku' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
///////////
I have also shared a log with you -
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'heroku',
1 verbose cli 'create',
1 verbose cli 'expense-tracker'
1 verbose cli ]
2 info using npm@6.14.12
3 info using node@v14.16.1
4 verbose stack Error: missing script: heroku
4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:155:19)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:63:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:116:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:436:5
4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:391:45)
4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:434:3)
4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:161:5)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:382:12
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:123:16
4 verbose stack at FSReqCallback.readFileAfterClose as oncomplete
5 verbose cwd C:\learning\React\react-complete-guide
6 verbose Windows_NT 10.0.18363
7 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "heroku" "create" "expense-tracker"
8 verbose node v14.16.1
9 verbose npm v6.14.12
10 error missing script: heroku
11 verbose exit [ 1, true ]
Hi I'm having a hard time deploying my react app to heroku. I noticed you don't have a build folder, or a server folder.
Should i delete those before trying this method?
You didn't mention anything about the Procfile which is the most important thing when you deploying a react project.
Thanks for the write up - it was super helpful!
I admit... you got me putting the easy way in the bottom of the article. Sometimes, its better to learn the hard way.
Thanks. This with Nitin comment dev.to/niinpatel/comment/5b6p saved me after several hours
I am getting 404 not found nginx .
Please Help
I was getting the same thing too....until i tried the easier method he provided us
This guide is human-friendly. So much trash out there. Thanks man 👌
hello guy! i'm now deplyed my app in heroku ! what a doing after?
I am having an issue. Getting “failed to push some refs” when trying to push.
stackoverflow.com/questions/584958...
Hey, i followed all the steps but some reason heroku is displaying the default template app that is created when you first create a react app, As opposed to my app. What am i doing wrong ?
Some comments may only be visible to logged-in visitors. Sign in to view all comments.