MuhdHanish / git_actions_nodejs

This repository serves as a learning resource for Continuous Integration and Continuous Deployment (CI/CD) in the context of a simple Node.js server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploy Nodejs project to Amazon EC2 with Github Actions

After successfully connecting github to remote server follow this commands

Step 1: Update Package Repositories

Run the following command to update your package repositories:

sudo apt update

Step 2: Install Node.js

Install Node.js using the following command:

sudo apt-get install -y nodejs

Step 3: Install Nginx

Install Nginx to act as a reverse proxy for your Node.js application:

sudo apt-get install -y nginx

Step 4: Install PM2

Install PM2 globally to manage your Node.js application:

sudo npm i -g pm2

Step 5: Configure Nginx

Navigate to the Nginx sites-available directory and open the default configuration file for editing:

cd /etc/nginx/sites-available
sudo nano default

Inside the Nginx configuration file, add the following block to configure the reverse proxy for your API:

location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Step 6: Restart Nginx

After making changes to the Nginx configuration, restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 7: Start Your Node.js Application with PM2

Navigate to your project directory and start your Node.js application using PM2. Replace server.js with the actual filename of your Node.js application:

cd /path/to/your/app
pm2 start server.js --name=server

Step 8: Restart Your Node.js Application with PM2 (Optional)

If you need to restart your Node.js application managed by PM2, you can use the following command:

pm2 restart server

These steps should help you set up a Node.js backend API with Nginx and PM2 on your Debian-based Linux system. Make sure to customize the paths and filenames according to your specific project.

About

This repository serves as a learning resource for Continuous Integration and Continuous Deployment (CI/CD) in the context of a simple Node.js server.


Languages

Language:JavaScript 100.0%