This post was written back in the days where Heroku provided free hosting; do not expect any example projects or links to Heroku to work.
This guide is step #2, written to assist my group in getting our team’s full stack app deployed. This post will focus on the React frontend; to get a Node backend deployed to Heroku first, please follow part 1, and to tie it all together check out part 3 .
# extract regular files and folders from inner folder
mv gigboard/gigboard-client/* gigboard/
# extract hidden files (those starting with dots) from the inner folder
mv gigboard/gigboard-client/.* gigboard/
process.env.NODE_ENV set to the string “production” in the deployed production app. To setup the alternate local development URL, you once again create a .env file, add the following line, and save:# inside your local .env file, which is gitignored
NODE_ENV='development'
Then in app.js or wherever we will be making API calls using fetch or axios, we can set this API_URL dynamically based on where the code is running.
let API_URL;
if (process.env.NODE_ENV === 'development') {
API_URL = 'http://localhost:5000';
} else if (process.env.NODE_ENV === 'production') {
API_URL = 'https://{{{YOUR-BACKEND}}}.herokuapp.com';
}
I used port 5000 because that seemed to be where heroku local web was serving the backend; if you’ll be using nodemon you’ll want to use whatever you’ve coded into your local backend development server. I found this 5000 vs 3001 issue because I was getting a net::ERR_CONNECTION_REFUSED error in the dev tools.
I needed to delete the yarn lock file; not sure why that was there but Heroku didn’t like having it and a package lock file at the same time.
I spent a lot of time researching getting two distinct .git repos to both push to a single Heroku app. I couldn’t remember if we were wanting this for sure, and the link he provided didn’t work as it was using heroku create which attempts to create a new app. I ended up giving up on trying for a single deployed app, and decided for sake of finally sleeping to just deploy this front end to a 2nd, separate Heroku app. The following process is almost the same as my first post on deploying backend .
first in browser
https://github.com/mars/create-react-app-buildpack.git into the input and click “save changes”
then in your command line
navigate to your frontend folder, and make sure you’re on your main branch.
git pull
npm i to make sure all your node modules are installed
make sure you can run the React app locally by running npm start and watching localhost:5000 in your browser.
heroku login back in your command line, press any button, log in with the browser that pops up, then close that browser window
you can also do a local test run with heroku local web if you’d like; make sure you kill anything running on port 5000 first.
heroku git:remote -a YOUR-FRONTED-HEROKU-APP-NAME and replace YOUR-FRONTED-HEROKU-APP-NAME with whatever the exact name of this new, front-end Heroku app is that you just made. For instance, mine is was deployed to gig-board.herokuapp.com so I will use gig-board.
git add .
git commit -am "make it work for frontend too, please"
git push heroku main
cross your toes and your eyes and wait until you hopefully see remote: Verifying deploy... done. This took significantly longer than the backend to deploy for me.
type heroku open and view your majestic nav bar.