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.
-
Sign in to your AWS account and navigate to the EC2 dashboard.
-
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.
-
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.
-
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.
-
Review and launch the instance. Choose an existing key pair or create a new one to access the instance securely via SSH.
-
Once the instance is launched, note down the public IP address or DNS name of the instance to access it via SSH.
- 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.
- 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.
- 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.
- 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.
-
Clone your NodeJS application repository or copy the application files to the EC2 instance using SCP or any other file transfer method.
- 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.
- Start the NodeJS application by running the following command:
node app.js
Replace app.js
with the main file of your NodeJS application.
-
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.
- 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.
Subscribe to our channel and press the bell icon for latest news updates: https://www.youtube.com/channel/UCK3qnCGyLZsVO-p7is2_yLg
How to deploy Node js in window
Use a tool like pm2 with ngnix is better for production
thank you… only works on port 80… i am using ports other than 80 and it not working, can anyone tell me the reason???
@CacheCloud, why did you use root user instead of sudo/admin, is there a reason ?
why not make it run on the background? now when you exit from terminal it will crash
Monk in cloud ki video???😅😂 Se seekh k apne channel se publish?
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
so, basically, we push code from local to github, then after that, we go to remote and pull code from github to run?
What if I want to add env variables how do I do that?
Let's say I have a docker image that gets a version of nodejs, do I still need to install nodejs again?
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?
how to add .env variables?
Thank You! But the server stop automatically as the session closes. i don't want that. i want it to run forever
Thank you very much It's very Excellent program❤❤❤
Very very nice
Excellent 👍