How to Deploy NodeJS App on AWS EC2 instance | Run App as Background Service Using PM2 | Full Demo

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to my YouTube channel in the today's video we will see how we can deploy or host our node.js app onto the ec2 instance I will use the Ubuntu operating system in the AC to instance so let's start with the video so as you can see this is a sample node.js app and currently it's listening on 3000 Port so as you can see this is listening on 3000 port code Sagar API so we will host this project onto the ec2 instance so first we need our ec2 instance this is my AWS account and I have already created a ec2 instance if you don't know how to create a easy tune stance so you can go to my YouTube channel I have already created a video on how to create a easy tune stance on AWS so you can follow this video to create a ec2 instance so first let's connect to the ec2 instance via terminal so we will use this command so in this command you can replace your Pam file and replace this public address of your ec2 instance click enter to connect enter your password so we are now connected to the ec2 installs so you can see we are using Ubuntu 22.04 version so first we have to install the node.js so we can use this command to install the node.js so here is the node.js version I am installing 16 version of node.js this will take some time so after this command you have to run this command sudo apt install node.js you can copy this command from here and paste press enter so this will install the node.js into the ec2 instance so let's check the version of node you can use command node version so we have installed 16 .20 version and we can check the version of npm also we are using 8.19 version so in this way we can install the node.js clear the console so next step we have to clone the code from the GitHub I have pushed this code onto the GitHub so as you can see this is the Repository simply click on code and copy the URL and you can type command sudo get clone and paste the URL press enter type LS go to this Repository CD node LS so you can see the files so first we have to install the dependencies we can use a command so do npm install this will install the dependencies so after that we can use command node app.js to run the project we have started this project and currently it's listening on 3000 to access this project we can use the public address of ec2 so you can go to your instance and copy this public IP and paste after that you have to add 3000 So currently we are not able to access this to make this work so next we have to open this port on our ec2 instance so we can go to ec2 instance and click on the security tab and then click on the security group so scroll down and in the inbound rules click on edit inbound rules and you can open the port 3000 from here click add rule select custom TCP I want to open 3000 port for everyone save this rule let's try to access the port 3000 now so as you can see we are able to get the response from the node.js app So currently we are using the node command to run the app so to run this process as a background service we will use the PM tool so let's install the pm2 stop this process for now let's install the pm2 we can use this command sudo npm install pm2 next we can install the logger data so this will delete the logs of pm2 after a certain period of time to start the node.js app in the pm2 we can use command sudo pm2 start app.js minus minus name and then we can add the name of the process node app press enter so you can see this will start the background process as a service so you can check the logs also sudo pm2 logs and then the ID of the process one Ctrl C to exit so let's check if the apis are working so you can see AP is a working fine so in this way you can host your node.js application onto the AC to installs clear the console so in the next step we will see how we can add our domain name instead of this IP so if you like this video don't forget to like And subscribe to my YouTube channel thanks for watching
Info
Channel: Code Sagar
Views: 5,108
Rating: undefined out of 5
Keywords:
Id: KVmKM6MxvcA
Channel Id: undefined
Length: 7min 23sec (443 seconds)
Published: Thu May 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.