A few steps that may come in handy when deploying your fullstack React app.
Server.js We will create a static build folder for the front end. This will be your React app. We need to tell the server where this will be so in your server.js file, add this:
//server.js
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
Run the yarn command from your root folder:
yarn run build
Now we have to add that build folder to your git so Heroku has access to it.
git add client/build
git commit -m 'Adding staticbuildfolder'
Create your Heroku app. Note, you need to install the Heroku toolbelt (https://blog.heroku.com/the_heroku_toolbelt)
heroku apps:create NAME_OF_APP
Now you need to push your app to Heroku.
git push heroku master
To connect to your database, you will have to provision Heroku with that database.
For Mongo, I tend to use MongoLab: https://devcenter.heroku.com/articles/mongolab
For SQL, you can use ClearDb. https://devcenter.heroku.com/articles/cleardb
You will have to update your connection string in your server to make this wok.
To view the Heroku logs use
heroku logs --tail
I hope you enjoyed this installment of Zack knows some stuff. I'm a developer, founder, lecturer
https://facebook.com/ransomly
https://instagram.com/positivelyZack
https://instagram.com/ransomly_inc