Deploying a Node.js app from Windows → WSL → AWS EC2, step-by-step, clearly and cleanly.
Simple Analogy: EC2 is the house. Apache is the kitchen. You install Apache inside EC2 to “cook” your web content.
Deploy your local Node.js app (port 5001) to AWS EC2 using WSL and rsync
.
npm install
npm start
Visit: http://localhost:5001
wsl --install
Then restart and install rsync:
sudo apt update
sudo apt install rsync
cd "/mnt/c/Users/Dell Inspiron/Documents/GitHub/node-express-ec2"
cp "/mnt/c/Users/Dell Inspiron/.ssh/ssh1.pem" ~/.ssh/
chmod 400 ~/.ssh/ssh1.pem
rsync -avz --exclude 'node_modules' --exclude '.git' --exclude '.env' \
-e "ssh -i ~/.ssh/ssh1.pem" \
. ubuntu@ec2-YOUR-PUBLIC-IP.compute-1.amazonaws.com:~/app
ssh -i ~/.ssh/ssh1.pem ubuntu@ec2-YOUR-PUBLIC-IP.compute-1.amazonaws.com
cd ~/app
sudo apt update
sudo apt install -y nodejs npm
npm install
npm start
Update Inbound Rules in EC2 to allow port 5001, then visit:
http://EC2_PUBLIC_IP:5001
you can absolutely add security to your EC2-hosted Node.js app and turn http into https by adding SSL/TLS encryption — which gives you that little padlock in the browser and serves your app over https://. Here’s how to do it using Let's Encrypt (free SSL certificates) with Nginx as a reverse proxy — the most common and recommended approach for a production-like setup.
need add more doucment below...nano deploy.sh
Paste this:
#!/bin/bash
KEY_PATH="$HOME/.ssh/ssh1.pem"
REMOTE_USER="ubuntu"
REMOTE_HOST="ec2-YOUR-PUBLIC-IP.compute-1.amazonaws.com"
REMOTE_DIR="~/app"
echo "🚀 Starting deployment to $REMOTE_HOST"
rsync -avz --exclude 'node_modules' --exclude '.git' --exclude '.env' \
-e "ssh -i $KEY_PATH" \
. $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR
echo "✅ Code synced. Logging into EC2..."
ssh -i $KEY_PATH $REMOTE_USER@$REMOTE_HOST << 'EOF'
cd ~/app
npm install
npm start
EOF
chmod +x deploy.sh
./deploy.sh