Wednesday, July 3, 2024
HomeLanguagesAWSDeploy Node js Express Application in AWS EC2 Server

Deploy Node js Express Application in AWS EC2 Server

Aws ec2 instance, deploy node js express app; In this tutorial, you will learn how to deploy node js express app on amazon aws ec2 instance.

How to Deploy Node JS Express Application on AWS EC2 Instance Free

Steps to create/launch ec2 instance and deploy node js + express application in aws ec2 free:

  • Step 1: Login to the aws console
  • Step 2: Choose Launch Instance
  • Step 3: Choose AMI
  • Step 4: Choose EC2 Instance Types
  • Step 5: Configure Instance Details
  • Step 6: Add Storage of Ec2 Intance
  • Step 7: Tag Instance of Ec2 Instance
  • Step 8: Configure Security Groups
  • Step 9: Review Instances
  • Step 10: Create Key-Pair For Intance Access
  • Step 11: Connect Instance to Terminal Using Putty
  • Step 12: Install NodeJS and Deploy your Application

Step 1: Login to the aws console

Use this link https://console.aws.amazon.com/ec2/ to login in your aws console account.

Step 2: Choose Launch Instance

First of all, Click on ‘Launch Instance’ button shows in the below picture for launch/create new ec2 intance in aws:

Step 3: Choose AMI

In this step, choose AMI according to your need. Here, we will choose Ubuntu server 18.04 LTS – SSD Value Type.

Step 4: Choose EC2 Instance Types

In this step, choose ec2 instance type shown in below picture:

Step 5: Configure Instance Details

In this step, you need to configure your instance. Like below given picture:

Step 6: Add Storage of Ec2 Intance

In this step, choose storage. By default ec2 t2-micro provide 8gb ssd. But you can change according to your need. Shown in the below picture:

Step 7: Tag Instance of Ec2 Instance

In this step, you need to add tag of instance with a key-value pair.

Like below given picture:

Step 8: Configure Security Groups

In this next step of configuring Security Groups, you can restrict traffic on your instance ports.

  1. Creating a new Security Group
  2. Naming our Security Group for easier reference
  3. Defining protocols which we want enabled on my instance
  4. Once, the firewall rules are set- Review and launch

Step 9: Review Instances

In this step, you need to review all settings and parameters. Then click on launch button:

Step 10: Create Key-Pair For Intance Access

In this step, you will be asked to create a key pair for login into your aws instance. A key pair is a set of public-private keys.

So, create new key pair and add the name of this key. Then download and save it in your secured folder.

Click on the Launch instances button to launch your instance. And wait a few minutes to completely launch your instance or web server.

Step 11: Connect Instance to Terminal Using Putty

Connect aws ec2 instance via ssh for Windows, mac and linux user.

Step 12: Install NodeJS and Deploy your Application

Once you are connected to your aws ec2 instance with terminal or ssh, update the packages by running the command:

sudo apt-get update

Then install the latest version of NodeJS by running the following commands:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Confirm NodeJS is install by checking the version of NodeJs installed with this command:

node -v

Next install git with the following command:

sudo apt-get install git

Git is a free and open-source distributed version control system. You will clone a git repository containing a simple node app from Github, modify it and deploy. Git might already be installed on the instance.

Clone the Node app files by running:

git clone https://github.com/neveropen/Simple-Node-JS-App.git

Navigate to the directory with:

cd node-app

Then install Node dependencies which will create the node-modules folder by running:

npm install

Your application can now be deployed live when you run:

node index.js

The app is running as soon as you open the terminal and it will terminate as you will close the terminal. you will install PM2 (Production manager 2) to keep live our app after closing our terminal or disconnect from the remote server. Run the following command:

sudo npm install pm2 -g

PM2 will be installed on the server globally. Run your app using PM2:

sudo pm2 start index.js

Thanks for reading this tutorial on how to deploy nodejs app on amazon ec2 instance.

Recommended AWS Tutorials

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments