Deploying a Node Js Application on AWS EC2
Are you a developer looking to host your Node.js app on AWS? In this guide, I’ll walk you through deploying and exposing a Node.js application on AWS EC2—perfect for beginners!
Before we start, make sure you have:
✔ AWS Free Tier account (or an existing AWS account)
✔ Basic knowledge of Linux commands (we’ll use Ubuntu)
✔ A Node.js app (or use a simple express demo)
🚀Step 1: Launch an EC2 Instance
1. Go to AWS EC2 Console
2. Configure Your Instance
3. Allow HTTP Traffic (IMPORTANT!)
4. Launch Instance
🔑Step 2: SSH into Your EC2 Instance
1. Find Your Instance’s Public IP
2. Connect via SSH
chmod 400 your-key.pem # Secure your key
ssh -i "your-key.pem" ubuntu@YOUR_PUBLIC_IP
✅ You’re now inside your EC2 server!
🛠️ Step 3: Install Node.js & NPM
1. Update Ubuntu Packages
sudo apt update
2. Install Node.js (Latest LTS Version)
sudo apt install nodejs
3. Verify Installation
node -v
OutPut :
Output
v12.22.9
4. Install npm
sudo apt install npm
Recommended by LinkedIn
📦 Step 4: Deploy Your Node.js App
1. Clone Your App (or Create a Demo One)
git clone YOUR_GITHUB_REPO_URL
cd your-app
npm install
npm run start
Open http://YOUR_EC2_IP:3000 in a browser → Should see "Hello AWS!"
NOTE - We will have to edit the inbound rules in the security group of our EC2, in order to allow traffic from our particular port
⚡ Step 5: Keep Node.js Running Forever (PM2)
1. Install PM2 (Process Manager)
sudo npm install -g pm2
2. Start Your App with PM2
pm2 start server.js --name "node-app"
3. Auto-Start on Reboot
pm2 startup
pm2 save
✅ Now your app will survive server crashes/reboots!
🌍 Step 6: Expose Your App to the Internet (NGINX Reverse Proxy)
1. Install NGINX
sudo apt install nginx -y
2. Configure NGINX
sudo nano /etc/nginx/sites-available/default
Replace the file with:
server {
listen 80;
server_name YOUR_PUBLIC_IP;
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;
}
}
Save (CTRL+X → Y → Enter)
3. Restart NGINX
sudo systemctl restart nginx
🎉 Now visit http://YOUR_PUBLIC_IP (no port needed!)
🔒 (Optional) Secure with HTTPS (Free SSL via Let’s Encrypt)
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d YOUR_DOMAIN.com # (or use IP)
✅ Your app now has HTTPS!
!
📢 Final Thoughts
You just: ✔ Deployed a Node.js app on AWS EC2 ✔ Made it publicly accessible ✔ Added auto-restart (PM2) + HTTPS
Next Steps?
Need help? DM me for freelance DevOps support! 🚀
👉 Like & Repost if this helped you! 👉 Follow for more AWS/DevOps guides.
#AWS #DevOps #NodeJS #CloudComputing #WebDevelopment