• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • AI
  • Javascript
  • TypeScript
  • Development
  • Frameworks
    • Angular
    • Git
    • NestJs

The code Mood

Ignite Passion, Master Code

You are here: Home / NestJs / How to Deploy a NestJS App on AWS EC2 in 2025

How to Deploy a NestJS App on AWS EC2 in 2025

by Ahmed Fakhar Abbas

So, you’ve built an awesome NestJS app. Now comes the fun part: making it live for the world to see! But let’s be real—deploying to AWS EC2 can feel like assembling IKEA furniture without the manual.

Don’t worry. I’ve burned my fingers so you don’t have to. By the end of this guide, your app will be humming on AWS EC2 like it’s hosting a Grammy after-party. Let’s go!’

Table of Contents

Toggle
  •  What You’ll Need
  • Update the System and Install Dependencies
  • Install Node.js and NPM using NVM
  • Install Git and Clone Your Repository
  • Start Your NestJS Project
  • Set Up Nginx as a Reverse Proxy
  • Update inbound role

 What You’ll Need

  • An AWS account (If you’re new, grab the free tier)
  • An EC2 instance 
  • Your NestJS code on GitHub (if not available you can use mine one for now)

Update the System and Install Dependencies

First, log in to your EC2 instance using SSH and run the following command to update and upgrade your system

sudo apt update && sudo apt upgrade -y

Install Node.js and NPM using NVM

Since AWS EC2 doesn’t come with Node.js pre-installed, we will install Node Version Manager (NVM), which allows us to install and manage Node.js versions easily.

Switch to the root user and install NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

This will loads nvm.

. ~/.nvm/nvm.sh 

Now, install Node.js (version 20):

nvm i 20

Verify the installation:

node -v
npm -v


Install Git and Clone Your Repository

Git is needed to fetch your project from GitHub. Install it using:

sudo apt-get update -y
sudo apt-get install git -y

Check if Git is installed correctly:

git --version

Now, clone your NestJS project from GitHub (replace the URL with your repository link):

git clone https://github.com/AhmedFakharABbas/graphql-nest-api.git

Move into the project directory:

cd nodejs-on-ec2

Install project dependencies:

npm install

Start Your NestJS Project

Now, it’s time to start your application! Run the following command:

npm start

If everything is set up correctly, your application should now be running!

sudo apt update && sudo apt upgrade -y

Set Up Nginx as a Reverse Proxy

sudo apt update
sudo apt install nginx
systemctl status nginx
curl -4 icanhazip.com
sudo chown -R $USER:$USER /home/ubuntu/graphql-nest-api
sudo chmod -R 755 /home/ubuntu/graphql-nest-api
sudo nano /etc/nginx/sites-available/gqlnestapi

server { 
        listen 80; 
        listen [::]:80;

        server_name 18.175.168.146;
        location / {
                 proxy_pass http://localhost:3000;
                 }
 }
sudo ln -s /etc/nginx/sites-available/gqlnestapi /etc/nginx/s_tes-enabled/
sudo nano /etc/nginx/nginx.conf
server_names_hash_bucket_size 64;
sudo nginx -t
sudo systemctl restart nginx

Update inbound role

Allow trafic from any part of the world! from your inbut roles

Filed Under: NestJs

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • 5 Programming Jokes That Prove Java Developers Have the Best Sense of Humor
  • Bridging the Gap: The Crucial Role of Developer Advocates in the Software Landscape
  • Long Hair and Beard: 9 Fascinating Secrets Behind Programmers’ Iconic Look
  • ServiceNow vs Salesforce: 7 Must-Know Differences to Choose the Best CRM Solution
  • Will Devin AI Take Your Job?

Categories

  • AI
  • Angular
  • Development
  • Git
  • Javascript
  • NestJs
  • TypeScript

Footer

  • About Us
  • Privacy Policy
  • Contact Us

Copyright © 2026 · The code Mood