Creating AWS EC2 Instance and Install Node Essentials.

Divyanshu Agarwal
4 min readMar 13, 2021

as an asynchronous event-driven JavaScript runtime. It is designed to build scalable network applications.

is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale computing easier for developers.

Leveraging the capabilities of both we aim to deploy applications which are fast , highly scalable, easy to deploy and secure.

Creating EC2 Instance.

Step 1: Choose your EC2 Instance.

1. Login to your aws console and select EC2 from services dropdown present on the left hand side in header section.

2. Select on launch instance from EC2 dashboard. As shown below:

3. Choose your instance carefully form the screen following it. For this tutorial i have selected :

Amazon Linux 2 AMI (HVM), SSD Volume Type — ami-081bb417559035fe8 (64-bit x86) / ami-0c5ce28df130113cb (64-bit Arm)

4. Choose the instance type from the next window. For the beginners and people who are just using it as hobby i would suggest them to select t2.micro. Once, you have selected the instance type you want click on the Review and Launch button present in the footer section.

5. Once you have confirmed the settings , click on the launch button present on right side in the footer section .

6. You will then be asked to add a key pair. It is necessary to either provide existing key pair or create a new pair in order to connect with the instance remotely.

7. Once you have created a new Instance. It will take 2–5 minutes before its in running state. Select the instance, Click on the Connect button on right side of the instance name.

Establishing the connection with EC2

To connect with ec2 in windows you need to have putty configured. Click here to understand the procedure for the same.

In case of MacOs and other linux based Os like ubuntu, you need to open your terminal and follow the procedure mentioned in current screen visible on your ec2 dashboard

Or follow the following steps

sudo chmod 400 relative_path_to_my_pem_key.pemssh -i "relative_path_to_my_pem_key.pem" ec2-user@your_public_dns_name.compute.amazonaws.com

In case you get the following message

Are you sure you want to continue connecting (yes/no/[fingerprint])?

Write yes and enter

Installing Node Essentials

Now you have established the connection with your ec2 instance. We can now proceed with Node installation.

Step 1. Installing NVM

Run following command.

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

We, now need to export nvm config. Although, after installing nvm using above command following lines are already added to ~/.bashrc . we still need to either run them manually run them again.

export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

or you could just reload ~/.bashrc

source ~/.bashrcor . ~/.bashrc

Check, if nvm has been properly installed

nvm --version

Expected output:

0.34.0

Now we can safely install any node version we like.

nvm install node   ## installs latest node versionnvm install --lts  ## installs latest LTS node Versionnvm install 12     ## installs latest version of 12th series of nodenvm install 12.21.1  ## installs the specific version

Verify node and nvm:

node -v && npm -v

Expected output

v12.21.06.14.11

is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

Run following command to install pm2 gloablly

npm i -g pm2

Check, if pm2 is installed properly

pm2 -v

Expected Output:

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\______\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\____\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\___\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/____\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//______\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//_________\/\\\_____________\/\\\_____________\/\\\___/\\\/____________\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\__\///______________\///______________\///__\///////////////__Runtime EditionPM2 is a Production Process Manager for Node.js applicationswith a built-in Load Balancer.Start and Daemonize any application:$ pm2 start app.jsLoad Balance 4 instances of api.js:$ pm2 start api.js -i 4Monitor in production:$ pm2 monitorMake pm2 auto-boot at server restart:$ pm2 startupTo go further checkout:http://pm2.io/-------------[PM2] Spawning PM2 daemon with pm2_home=/home/ec2-user/.pm2[PM2] PM2 Successfully daemonized4.5.5

--

--