Skip to content

The goal of this project is to practice setting up a CI/CD pipeline for a Node.js service using GitHub Actions. You will practice using GitHub Actions for deployment (including Secrets and environment variables), Terraform to provision a server, Ansible to configure the server, and SSH to deploy the application.

Notifications You must be signed in to change notification settings

GeigerJR/nodejs-deploy-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ Node.js Deploy Example – Project Documentation

A simple Node.js web server app deployed on an AWS EC2 instance. This project demonstrates the fundamental process of deploying a Node.js app on a cloud server.


πŸ“ Project Structure

nodejs-deploy-example/
β”œβ”€β”€ index.js        # Main Node.js server script
β”œβ”€β”€ README.md       # Project documentation

βš™οΈ Requirements

  • Node.js (v18+)
  • npm (v10+)
  • Git
  • AWS EC2 Instance (Ubuntu)
  • Nginx (optional for reverse proxy)
  • PM2 (optional for process manager)

πŸš€ Setup Instructions

1. Clone the GitHub Repository

git clone https://github.com/GeigerJR/nodejs-deploy-example.git
cd nodejs-deploy-example

2. Install Node.js and npm

sudo apt update
sudo apt install -y nodejs npm

3. Create the Node.js Server

nano index.js

Paste the code below:

const http = require('http');
const PORT = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.end('Hello from your Node.js server on EC2!');
});

server.listen(PORT, () => {
  console.log(`Server running at http://localhost:${PORT}/`);
});

Save and exit: CTRL + O, ENTER, then CTRL + X


4. Start the Server

node index.js

Then visit:

http://<your-ec2-public-ip>:3000

πŸ“¦ Optional: Use PM2 for Process Management

Install and use PM2 to keep the app running even after terminal logout:

sudo npm install -g pm2
pm2 start index.js
pm2 save
pm2 startup

🌐 Optional: NGINX Reverse Proxy Setup

Install Nginx:

sudo apt install nginx

Configure reverse proxy:

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

Replace the location / block:

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

Restart Nginx:

sudo systemctl restart nginx

Visit your EC2 Public IP in the browser (http://<your-ec2-ip>).


πŸ“ Update and Push README to GitHub

Create the README:

nano README.md

Paste in all content from this note, then:

git add README.md
git commit -m "Add full project documentation"
git push origin main

πŸ‘€ Author

About

The goal of this project is to practice setting up a CI/CD pipeline for a Node.js service using GitHub Actions. You will practice using GitHub Actions for deployment (including Secrets and environment variables), Terraform to provision a server, Ansible to configure the server, and SSH to deploy the application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published