How to Run a Node JS Server on AWS EC2 (Step-by-Step Guide)

In this article, I will show you how to run a simple Node.js server on your AWS EC2 Ubuntu instance step-by-step.
â„šī¸
📌 Prerequisite I am assuming you have already created an EC2 Linux/Ubuntu Instance. If not, follow this step-by-step guide:
👉 How to Create an AWS EC2 Instance.
After creating your EC2 instance, it is recommended to set up FileZilla and PuTTY for easier server access. If not configured yet, follow these guides:
👉 Access AWS EC2 Instance using FileZilla
👉 Access AWS EC2 Instance using PuTTY
🔄 Step 1: Update the Server & Install Node.js
After connecting to your EC2 instance via SSH, first update the system packages and install Node.js and npm.
sudo apt-get update
sudo apt-get install nodejs npm -y

node -v
npm -v
📁 Step 2: Create Project Folder
Now create a working directory for your Node.js project.
mkdir codingfolder
cd codingfolder

mkdir nodeapp
cd nodeapp
Your server will later be accessible using your EC2 Public IP like:


http://3.140.251.200:3000
đŸ“Ļ Step 3: Initialize Node.js Project
Initialize a new Node.js project using npm.
npm init -y
📝 Step 4: Create Server File
Create a simple server file using Express.js.
npm install express
sudo vi server.js
đŸ’ģ Step 5: Add Node.js Server Code
Paste the following simple Express server inside server.js:
const express = require('express');
const app = express();

const PORT = 3000;

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(PORT, '0.0.0.0', () => {
    console.log(`Server running on port ${PORT}`);
});
🚀 Step 6: Run the Node.js Server
Now start your Node.js server:
node server.js
Once the server is running, open your browser and access:


http://44.203.192.53:3000
âš ī¸ Make sure port 3000 is allowed in your EC2 Security Group inbound rules.
✅ Success!
Congratulations 🎉 Your Node.js server is now running on AWS EC2.


You can now build REST APIs, connect databases, or deploy production-ready applications using PM2 and Nginx.