Deploying Node Js Application on AWS EC2

In this blog we will deploy simple Node Js Application on AWS EC2

-- Open your terminal and clone the below given repository

git clone https://github.com/verma-kunal/AWS-Session

-- open the AWS-Session file in VS code and open terminal

-- create a new file with name .env (New-Item -ItemType file .env)

download the npm from the browser and after downloading run the below command to check if npm is installed or not

npm -version

-- open the .env file and enter the credentials like below

DOMAIN= ""

PORT=3000
STATIC_DIR="./client"

PUBLISHABLE_KEY=""

SECRET_KEY=""

note: publishable key and secret key you will get it from the stripe https://dashboard.stripe.com/apikeys

-- now run the command npm run start

-- try to access it in localhost

Create a user and give admin access

-- login to aws account and create a user account with console access, password and admin access

Create a new EC2 instance

-- select ubuntu and and create and download a new keypair create EC2 instance

-- connect to ec2 instance with ssh client option

-- open terminal and go to the downloads folder where pem file is located, then execute the below commands

ssh -i demo-nodejs.pem ubuntu@13.239.20.20

-- update the packages using

sudo apt update

-- now we have to clone the git repository using below

git clone https://github.com/verma-kunal/AWS-Session.git

-- Installing nodejs npm

use the link for steps: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-22-04

-- change the directory to the folder AWS-Session

cd AWS-Session

Create .env file and put all the credentials in that file

touch .env

-- if you are unable to view the file when you do ls, then use ls -a( to display all hidden files)

to edit the .env file use vim

vi .env

and enter the same configuration details which we entered for our system

-- now if you try to access the application using public ip of ec2 istnace, you will not be able to see the results, we need to add inbound security rules as follows

-- change the security group to allow 3000 port and save the changes and try again

hurray, we have successfully deployed our app on ec2