Note: these instructions are for React apps that have been created with the command
In a terminal, from any directory, run the following to install
npm install netlify-cli -g
If this fails with errors, run it again with superuser privileges, using
sudo npm install netlify-cli -g
Visit https://netlify.com/ and create a free account.
First navigate with
cd to the directory for your React app that you want to host. (Let's assume it's called cyf-hotel)
build the app:
npm run build
This will create (or update) a
build directory within your current directory. This contains a prepared version of your app, ready to be hosted. (There are many ways to host it.)
netlify deploy --prod
It will ask some questions.
NOTE: You can only use the keyboard (UP/DOWN arrows, and ENTER) to input the answers to these questions.
First it will try to use your browser to authenticate you. Depending on your computer, it may launch a new browser tab or it may fail to do so.
If told to do so:
open the given URL in the browser to authenticate
In all cases:
Go to your browser, press "Authenticate" on the netlify tab that has just been opened.
Go back to the terminal. It should display that auth was successful, and it should ask you more questions:
Create & Configure a new site
Choose a site name like:
When asked for team, DON'T select
CYF if it is an option. Choose your own user name as a team.
When asked for deploy path, enter
That's it, all done.
Visit the live site URL that netlify reports at the end.
Check your app is there and works!
Test it on your phone!
Share the url with someone in the class!
After you make changes, you will want to build and deploy again, in order to host your updated app. Here is how:
Make changes to your app
Test the changes
If you're ready to update the hosted version:
npm run buildnetlify deploy --prod
If you decide you don't want your site hosted:
log in to https://netlify.com/
select your site from the list
click on site settings
scroll down and choose delete this site
follow the instructions to confirm
To make updating your site easier, you can make some small adjustments (suggested by Jon R Sharpe):
You can specify the deploy directory in the Netlify
deploy command, by adding
--dir ./build. This way, it won't ask you to type it in.
netlify deploy --prod --dir ./build
You could make a custom command to do build and deploy together. Here's how:
package.json to add
"deploy": "npm run build && netlify deploy --prod --dir ./build" to the
scripts object. Then you can just run
npm run deploy and the build and deploy step will both be done for you. Be careful when you edit that file, and copy and paste exactly from here!