Scale customer reach and grow sales with AskHandle chatbot

How to Deploy a Simple Node.js App to AWS EC2?

Deploying a Node.js application on an AWS EC2 instance is a practical skill for web developers. It allows hosting scalable applications with control over the environment. This article provides a straightforward guide to getting your Node.js app up and running on AWS EC2.

image-1
Written by
Published onNovember 18, 2025
RSS Feed for BlogRSS Blog

How to Deploy a Node.js App to AWS EC2

Deploying a Node.js application to AWS EC2 gives you full control over your server environment, enabling scalable, flexible infrastructure for your backend or web applications. This guide walks you through each step—from launching your EC2 instance to making your app publicly accessible with Nginx and PM2.

1. Launching an EC2 Instance

Step 1 — Create/Log in to AWS

Go to the AWS Management Console → open EC2.

Step 2 — Launch a New Instance

  1. Click Launch Instance

  2. Choose an OS:

    • Amazon Linux 2 (recommended)
    • Ubuntu 22.04 LTS
  3. Instance type: t2.micro (Free Tier eligible)

  4. Key pair: Create or select an existing .pem key pair (you’ll need this to SSH into your server).

Step 3 — Configure Security Group

Allow the following inbound rules:

PortProtocolPurpose
22SSHFor remote login
80HTTPWeb access
443HTTPSSecure web access
3000 (optional)HTTPIf testing app directly

You can remove port 3000 later after Nginx is set up.

Launch the instance and wait for initialization. Note the Public IPv4 address or Public DNS.

2. Connecting to the EC2 Instance

From your computer terminal:

Set the key file permissions:

Bash

Connect:

Amazon Linux

Bash

Ubuntu

Bash

3. Install Node.js and npm

We install Node 18 LTS using NodeSource.


Amazon Linux 2

Update packages:

Bash

Install Node.js 18:

Bash

Ubuntu

Update:

Bash

Install Node.js 18:

Bash

Verify Installation

Bash

4. Upload Your Node.js App to EC2

You have 3 options:

Option A — Upload via SCP

Bash

Option B — Clone From GitHub

Bash

Option C — Use SFTP GUI Tools

(e.g., FileZilla, WinSCP)

5. Install Dependencies

Navigate into the project:

Bash

Install packages:

Bash

Ensure package.json has a start script:

Json

6. Run the App with PM2 (Process Manager)

Running node app.js manually stops when you close SSH. So install PM2, a production-ready process manager.

Install PM2

Bash

Start your app

Bash

Enable auto-start on OS reboot

Bash

(If using Ubuntu, replace user with ubuntu.)

Check running processes

Bash

7. Configure Nginx as a Reverse Proxy

Your Node.js app likely runs on port 3000, but websites use port 80/443.

Nginx will:

  • Accept requests on port 80
  • Forward them to port 3000

Install Nginx:

Amazon Linux:

Bash

Ubuntu:

Bash

Create the Proxy Configuration

Amazon Linux

Create a new config file:

Bash

Ubuntu

Edit the default site:

Bash

Paste this updated configuration:

Nginx

Save and exit.

Test Nginx configuration:

Bash

Restart Nginx:

Bash

Now open: http://your-ec2-public-ip

Your app is live 🎉

Install Certbot:

Amazon Linux:

Bash

Ubuntu:

Bash

Run:

Bash

Follow the prompts to enable HTTPS.

9. Hardening & Maintenance Tips

Firewall (Ubuntu only)

Bash

Keep server updated

Bash

Log rotation

PM2 handles logs automatically:

Bash

Final Result

You now have:

  • ✔ Node.js installed
  • ✔ Your app uploaded and dependencies installed
  • ✔ PM2 managing your app on startup
  • ✔ Nginx reverse proxy routing traffic
  • ✔ HTTPS enabled via Let’s Encrypt (optional)
  • ✔ A production-ready environment on EC2
NodeJSEC2Deploying
Create your AI Agent

Automate customer interactions in just minutes with your own AI Agent.

Featured posts

Subscribe to our newsletter

Achieve more with AI

Enhance your customer experience with an AI Agent today. Easy to set up, it seamlessly integrates into your everyday processes, delivering immediate results.

Latest posts

AskHandle Blog

Ideas, tips, guides, interviews, industry best practices, and news.

View all posts