,

Deploying a NodeJS App on an AWS EC2 Instance: A Comprehensive Tutorial from Cache Cloud

Posted by


In this tutorial, we will go through the steps to deploy a NodeJS application on an AWS EC2 instance. This process involves creating an EC2 instance, setting it up with NodeJS and deploying our application on it.

  1. Sign in to your AWS account and navigate to the EC2 dashboard.

  2. Click on ‘Launch Instance’ to create a new EC2 instance. Choose an Amazon Machine Image (AMI) that is suitable for your application, such as an Amazon Linux AMI.

  3. Select an instance type that meets your requirements, and configure the instance details as required. You can choose the default settings for networking, storage and other options.

  4. In the ‘Configure Security Group’ step, make sure to create a new security group with the necessary inbound rules to allow access to your application. For example, you can open ports 22 for SSH access and port 80 for HTTP access.

  5. Review and launch the instance. Choose an existing key pair or create a new one to access the instance securely via SSH.

  6. Once the instance is launched, note down the public IP address or DNS name of the instance to access it via SSH.

  7. Connect to the instance using the SSH key pair you selected during the instance launch. Use the following command to connect to the instance:
ssh -i /path/to/your-key.pem ec2-user@public-ip-address

Replace /path/to/your-key.pem with the path to your SSH key pair file and public-ip-address with the public IP address of your instance.

  1. Update the packages on the instance using the following command:
sudo yum update -y

This will ensure that the instance is up-to-date with the latest software packages.

  1. Install NodeJS on the instance using the following commands:
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install -y nodejs

This will install NodeJS version 14 on the EC2 instance.

  1. Verify the NodeJS installation by checking the version using the following command:
node --version

You should see the installed NodeJS version displayed in the output.

  1. Clone your NodeJS application repository or copy the application files to the EC2 instance using SCP or any other file transfer method.

  2. Install the application dependencies by navigating to the application directory and running the following command:
npm install

This will install all the required NodeJS modules and dependencies for your application.

  1. Start the NodeJS application by running the following command:
node app.js

Replace app.js with the main file of your NodeJS application.

  1. Access your NodeJS application using the public IP address or DNS name of the EC2 instance in a web browser. You should see your application up and running on the AWS EC2 instance.

  2. You can optionally set up a process manager like PM2 to keep your NodeJS application running in the background and handle process management tasks.

That’s it! You have successfully deployed your NodeJS application on an AWS EC2 instance. You can now access and use your application from anywhere in the world. Remember to monitor your application’s performance and security regularly to ensure smooth operation.

0 0 votes
Article Rating

Leave a Reply

17 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@CacheCloud
27 days ago

Subscribe to our channel and press the bell icon for latest news updates: https://www.youtube.com/channel/UCK3qnCGyLZsVO-p7is2_yLg

@Mohduvesh-kd3et
27 days ago

How to deploy Node js in window

@KrishnaDasPC
27 days ago

Use a tool like pm2 with ngnix is better for production

@farhad6365
27 days ago

thank you… only works on port 80… i am using ports other than 80 and it not working, can anyone tell me the reason???

@MrArunraja08
27 days ago

@CacheCloud, why did you use root user instead of sudo/admin, is there a reason ?

@mejiger
27 days ago

why not make it run on the background? now when you exit from terminal it will crash

@a.tech.3973
27 days ago

Monk in cloud ki video???😅😂 Se seekh k apne channel se publish?

@MuhammadBilal-hq3xn
27 days ago

Hello brother I followed same process and deployed the project but I have issues that it not running on public ip my port is 8080

@noctrz2408
27 days ago

so, basically, we push code from local to github, then after that, we go to remote and pull code from github to run?

@henzyd
27 days ago

What if I want to add env variables how do I do that?

@henzyd
27 days ago

Let's say I have a docker image that gets a version of nodejs, do I still need to install nodejs again?

@rafaelhernandez6632
27 days ago

I got the confirmation message that the node project started but my ip does not work, was there any paticular settings my ec2 instance needed?

@user-gn2pl2xm1f
27 days ago

how to add .env variables?

@valobhediya
27 days ago

Thank You! But the server stop automatically as the session closes. i don't want that. i want it to run forever

@amjadbutt4797
27 days ago

Thank you very much It's very Excellent program❤❤❤

@amjadbutt4797
27 days ago

Very very nice

@faisalmahmood8055
27 days ago

Excellent 👍

17
0
Would love your thoughts, please comment.x
()
x