Deploying NodeJS APP on AWS EC2 Instance — Step by Step (2024)

Hello there🌻

In this article, we are going to see how one can deploy a NodeJS application on an AWS EC2 Linux instance and access the same in the browser.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (2)

Before starting with the actual deployment process let’s have some introduction on the Node.js, AWS, EC2 and Linux AMI.

Node.js

It is a JavaScript runtime environment, written in C++. It allows users to run JavaScript on the server and to create server side applications with JavaScript.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (3)

It is mostly used for creating server-side APIs, and command-line tools and real-time applications.

AWS (Amazon Web Services)

AWS is a cloud computing platform which provided by Amazon.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (4)

It consists of various remote computing services like Amazon EC2 instances, various types of databases and networking options.

AWS EC2(Elastic Compute Cloud)

Amazon EC2 is Amazon Elastic Cloud Computing. This is a service where Amazon provides us a server where we can deploy our application for absolute minimum cost and it takes a very little time to do so.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (5)

By providing the service of AWS EC2 amazon is giving us a easy way to launch our application without worrying about the bare metal hardware stuff and the networking part.

Linux AMI

An Amazon Machine Image (AMI) is a pre-configured virtual machine image, available in the Amazon Web Services (AWS) ecosystem, that is used to launch an instance

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (6)

A Linux AMI comes pre-installed with a Linux operating system. Some of the most popular Linux distributions available AMIs on AWS are Ubuntu, Amazon Linux.

So the steps that we need to perform here are as follows:

  1. Create a AWS EC2 instance
  2. SSH into the instance
  3. Install NodeJS and NPM
  4. Install Git
  5. Clone the repository from GitHub
  6. Install all the required dependencies
  7. Run the application
  8. Access the application in browser

Now we will start performing all these steps one by one :

1. Create a AWS EC2 instance

As a very first step here in the process we need to configure a AWS EC2 instance and SSH into the same.

To know the process of configuring a EC2 instance please check my previous article on the same.

Here is the Link : “Launching your first EC2 Instance”

Now we will start the procedure of deploying the Node.js application on the newly created EC2 machine.

2. SSH into the instance

The steps to SSH into the EC2 machine has been explained in the previous article. Please check the link provided in 1st point.

After doing SSH into the EC2 instance you need to change the user to the super user by using the command :

#sudo su

so that you won’t have any user permission issues.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (7)

3. Install NodeJS and NPM using nvm

Now we need to install nvm (node version manager)by typing the following at the command line.

#curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (8)

Now you need to activate nvm by using the command :

#. ~/.nvm/nvm.sh

By using nvm you have to install Node.js. Put the below command in the command line :

#nvm install 16
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (9)

Check the nvm and Node.js version by using the commands

#nvm --version
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (10)
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (11)

4. Install Git

Now we need to take the source code of the Node.js application from the GitHub so we have to install Git first so that we can clone the particular repository of the Node.js application.

The #yum update -y command is used to update the existing software packages on the machine.

Use the below command to install Git on your machine :

#yum update -y
#hj
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (12)
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (13)
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (14)

You can check the version of the Git by putting the command

#git --version
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (15)

5. Clone the repository from GitHub

After installing Git, now we will clone the repository of the Node.js application.

REPO-LINK :

https://github.com/rajani103/nodejs-on-ec2

Use the below command to do so :

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (16)

This command will clone(creating a copy) the repository on the machine by creating a folder by the name “nodejs-on-ec2”.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (17)

Now get into that folder and check the sub folders and files of the Node.js application. Use the command to check the files:

#cd nodejs-on-ec2
#ls -ltr
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (18)

6. Install all the required dependencies

To install the dependencies use the below command :

#npm install
Deploying NodeJS APP on AWS EC2 Instance — Step by Step (19)

7. Run the application

To run the application put the below command in the command line :

#node index.js

8. Access the application in browser

As you can see in the repository on the GitHub in the index.js file we have already mentioned to create a http server which is listening on port 80.

So there is no need to doing the port mapping again, as we can easily access the application by using the public IP of the machine and port number 80.

If everything till now is working fine then we will be able to see the application running on the port number 80.

3.134.85.190:80
(public IP of the machine : port 80)

You can see the browser output below :

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (20)

You can also use the public DNS of the machine to get the access .

http://ec2-3-134-85-190.us-east-2.compute.amazonaws.com/:80

You will get the similar output.

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (21)

If I have made a mistake somewhere or missed any important point, do let me know in the comments.

If this post was helpful, please do follow and click the clap 👏 button below to show your support 😄

_ Thank you for reading💚

_Rajani 🌻✨

Deploying NodeJS APP on AWS EC2 Instance — Step by Step (2024)
Top Articles
Can You Sue Someone For Making False Accusations?
5.5. /var/cache : Application cache data
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 5617

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.