To update your Node.js application that's being managed by PM2 and hosted on a GitHub repository, follow these steps:
- Navigate to your application's directory:
Open a terminal and go to the directory where your Node.js application is located.
cd /path/to/your/nodejs/app
- Optionally stop the PM2 process:
You might want to stop your application before updating it to prevent any issues.
Replace
app_name_or_id
with the name or ID of your app's process in PM2.
- Pull the latest changes from GitHub:
Make sure you're on the right branch and then update your local code with the changes from GitHub.
git checkout main # or the branch you want to update
git pull origin main # replace 'main' with your desired branch if needed
- Install any new dependencies:
If the package.json
has been updated with new dependencies, you need to install them.
- Rebuild your application (if required):
If your application needs a build step, run the necessary command to build it.
npm run build # This command can vary depending on your app
- Restart your application with PM2:
Once everything is updated and built, you can restart your Node.js application with PM2.
pm2 restart app_name_or_id
That's it! Your Node.js app should now be updated to the latest version from the GitHub repository and running with the new changes.