🚀 Deploy Your Node.js App on AWS EC2 – A Hands-on Guide for Beginners

🚀 Deploy Your Node.js App on AWS EC2 – A Hands-on Guide for Beginners

Have a cool Node.js project running locally and wondering how to take it live on the internet? 🌍

Welcome to real-world deployment — where your code leaves your laptop and meets the world. In this guide, we’ll walk through deploying a Node.js application on AWS EC2, step by step. By the end, your app will be live, hosted, and ready for users — for free using the AWS free tier!

🧪 Step 1: Test the Node.js App Locally

Before deploying, verify that everything works on your local machine.

1️⃣ Clone the Repository

git clone https://github.com/verma-kunal/AWS-Session.git
cd AWS-Session        

2️⃣ Create a .env File

The .env file is used to store environment variables — key-value pairs that configure how your app runs without hardcoding sensitive or configurable values (like API keys, ports, etc.) directly into your code. This keeps your project secure and flexible across environments.

Inside your project root, create a file named .env:

DOMAIN=""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""        

These variables will be loaded into your app automatically when it runs.

3️⃣ Install Dependencies

npm install        

4️⃣ Start the App

npm run start        

Your app should now be running at: 👉 http://localhost:3000 .

☁️ Step 2: Launch an EC2 Instance on AWS

Time to host your app on the cloud!

1️⃣ Create an IAM User

  • Go to AWS Console > IAM
  • Create a new user
  • Enable Programmatic Access and Console Access
  • Attach the policy: AdministratorAccess

IAM (Identity and Access Management) is a security feature in AWS that lets you create users and control what they can and can’t do in your account.

An IAM user is a separate identity (not the root account) that you can use to log in and access AWS services securely. It's a best practice to avoid using the root user for day-to-day tasks.

Tip: Avoid using the root user for daily tasks.

2️⃣ Launch an EC2 Instance

  • Go to EC2 Dashboard > Launch Instance
  • Choose Ubuntu as the OS
  • Select t2.micro (free-tier eligible)
  • Create and download a new .pem key pair
  • Under Security Groups, allow traffic on port 3000


🔌 Step 3: Connect to EC2 via SSH

Once your instance is running:

ssh -i "your-key.pem" ubuntu@<YOUR_EC2_PUBLIC_IP>        

Replace:

  • your-key.pem with your downloaded key
  • <YOUR_EC2_PUBLIC_IP> with the actual public IP

🔧 Step 4: Set Up the Server Environment

1️⃣ Update Ubuntu Packages

sudo apt update        

2️⃣ Install Git

sudo apt install git        

3️⃣ Install Node.js & npm

sudo apt install nodejs npm        

Check versions to confirm:

npm -v        

🚀 Step 5: Deploy the Project on EC2

Now, bring your Node app to life on your EC2 server.

1️⃣ Clone the Repo Again (on EC2)

git clone https://github.com/verma-kunal/AWS-Session.git
cd AWS-Session        

2️⃣ Create a .env File

Update it with your server details:

DOMAIN="http://<your-ec2-elastic-ip>:3000"
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY="your_stripe_publishable_key"
SECRET_KEY="your_stripe_secret_key"        

3️⃣ Install Dependencies

npm install        

4️⃣ Start the App

npm run start        

Your app should now be accessible at:👉 http://<your-ec2-public-ip>:3000

🔐 Step 6: Allow External Access on Port 3000

If your app isn't loading in the browser:

  • Go to Security Groups
  • Edit Inbound Rules
  • Add rule:


🧠 Real-World Use Case

You’re building a startup and have a Node.js + Stripe-based billing app. You want users to try it out without spending on hosting. AWS EC2’s free-tier gives you a quick, reliable deployment path to test with real users — no cost upfront.

🎯 Final Thoughts

Cloud deployment might seem intimidating at first, but once you walk through it, you’ll see how powerful and accessible it really is.

✅ You just:

  • Tested a local Node.js app
  • Spun up a secure virtual machine
  • Configured your environment
  • Deployed your project live!

Give it a shot, and watch your app come alive on the internet 🚀

To view or add a comment, sign in

More articles by Swastideepa Dash

Others also viewed

Explore content categories