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
Complaints we can help with - Financial Ombudsman Service
Primary Market vs. Secondary Market: What's the Difference?
Food King El Paso Ads
Algebra Calculator Mathway
Wmu Course Offerings
Ati Capstone Orientation Video Quiz
How to Type German letters ä, ö, ü and the ß on your Keyboard
Stolen Touches Neva Altaj Read Online Free
13 The Musical Common Sense Media
Urban Dictionary Fov
Cincinnati Bearcats roll to 66-13 win over Eastern Kentucky in season-opener
Ukraine-Russia war: Latest updates
Slushy Beer Strain
Elizabethtown Mesothelioma Legal Question
Overton Funeral Home Waterloo Iowa
Eka Vore Portal
Cvb Location Code Lookup
Bnsf.com/Workforce Hub
Dtab Customs
Site : Storagealamogordo.com Easy Call
Rural King Credit Card Minimum Credit Score
/Www.usps.com/International/Passports.htm
BMW K1600GT (2017-on) Review | Speed, Specs & Prices
Mineral Wells Skyward
Meridian Owners Forum
Milwaukee Nickname Crossword Clue
Wood Chipper Rental Menards
Coindraw App
Lindy Kendra Scott Obituary
The Procurement Acronyms And Abbreviations That You Need To Know Short Forms Used In Procurement
The Bold and the Beautiful
Armor Crushing Weapon Crossword Clue
Gyeon Jahee
Texters Wish You Were Here
2016 Honda Accord Belt Diagram
To Give A Guarantee Promise Figgerits
USB C 3HDMI Dock UCN3278 (12 in 1)
Deshuesadero El Pulpo
Gary Lezak Annual Salary
Thothd Download
Brown launches digital hub to expand community, career exploration for students, alumni
Best Haircut Shop Near Me
John Wick: Kapitel 4 (2023)
Noga Funeral Home Obituaries
2294141287
Craigslist Chautauqua Ny
Read Love in Orbit - Chapter 2 - Page 974 | MangaBuddy
Provincial Freeman (Toronto and Chatham, ON: Mary Ann Shadd Cary (October 9, 1823 – June 5, 1893)), November 3, 1855, p. 1
Haunted Mansion Showtimes Near The Grand 14 - Ambassador
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.