Deploy Node JS App to Amazon AWS EC2

Deploy Node JS App to Amazon AWS EC2

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

Amazon launched Amazon Web Services(AWS) in 2006 with EC2 as the first public cloud service offering server instances on-demand by leveraging the power of virtualisation. Amazon logically divided the servers in their own data centre and added a software layer over it to create smaller logical servers which they called instances. An EC2 instance on AWS is now offered to the public as virtual machines on the web with configurable size, memory and networking which is available on-demand and billed per seconds. Erstwhile, any business or individual who needs a server has to purchase a physical server and maintain it on-premise, even if they only needed it for a few days in a month or even a year. Applications could also be deployed without having to host hardware or worry about scaling up or down as the need require. Through these tutorial steps, you’ll launch your own Amazon EC2 instance for free and depoly node js + express app on amazon aws ec2 instace..

Deploy a Node JS + Express app on AWS EC2

Use the following simple and easy steps to create/launch ec2 intance and deploy nodejs + express app on aws ec2:

  • 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/tutsmake/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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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