- Make sure code works on your local (unhosted) project.
- Add, commit, and push working changes to GitHub.
- In your command line editor, use the
ssh
command to connect to your server droplet and usecd
to go to your project folder on the server. - Use
git status
to show the status of your project on the server. It should be one (or more) commits behind the origin/master branch on GitHub since you just recently pushed new changes to GitHub which you have not yet pulled down onto the server. If it says you are up to date, you may need to rungit fetch
.git fetch
will not change any of your code; it merely refreshes Git's look at which files are up to date. - Use
git pull
to pull down the latest code changes onto your server. Your server now has working code. - Use
npm run build
for React projects which useexpress.static
to serve up files from a build folder. This recreates the build folder with the recent changes so they become part of the files that are served up. - Restart PM2.
- Installing new node modules in the local project should have changed your local package.json file. This file is not .gitignored, so you can update your hosted project's package.json file by following steps 1–5 above which describe how to push and pull working code to the server.
- Once package.json file is up to date on the server, run
npm install
to install the new dependencies into your project. - Use
npm run build
to make a new build folder so these changes become part of the code served up. - Restart PM2.
- Because these files are ignored by Git and will not be updated with
git pull
, they need to be updated manually. - If these files are at the top of the project folder, use
cd
to go to the top of the folder and usenano
to open the files (e.g.,nano .env
). - Type or paste in the edits to these files. Some of these edits can be pasted as is from your local .env or config files. Keep in mind, however, that when it comes to URLs, your local project might make use of absolute paths (e.g., 'http://localhost:3001/api/products') whereas your hosted project's .env and config files should generally use relative paths instead (e.g., '/api/products').
- Run
npm run build
to build these changes into your project. - Restart PM2.