Deploying Your First Node.js App on AWS EC2: A Beginner's Guide to Cloud Success
Title : Deploying Your First Node.js Application on AWS EC2 : A Step-by-Step Guide
Introduction:
In this Blog, we'll explore the process of deploying a Node.js application on AWS EC2. We'll cover the necessary steps to set up an EC2 instance, install Node.js, and deploy our application on the cloud.
Prerequisites:
Basic knowledge of Node.js and AWS
An AWS account with access to EC2
A Node.js application to deploy
Want to try this project at your end ? Fork the GitHub repo https://github.com/verma-kunal/AWS-Se...
Deploying a Node.js Application on AWS EC2
Testing the Project Locally first
Before deploying our Node.js application on AWS EC2, let's test it locally to ensure everything is working as expected.
- Clone the project from GitHub:
COPY
git clone https://github.com/verma-kunal/AWS-Session.git
- Set up the environment variables in a
.env
file:
COPY
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""
- Initialise and start the project:
COPY
npm install
npm run start
Open a web browser and navigate to http://localhost:3000
to verify that the application is running locally.
Setting up an AWS EC2 Instance
Now that our application is running locally, let's set up an AWS EC2 instance to deploy it.
Create an IAM user and log in to your AWS Console:
Access Type: Password
Permissions: Admin
Create an EC2 instance:
Select an OS image: Ubuntu
Create a new key pair and download the
.pem
fileInstance type: t2.micro
Connect to the instance using SSH:
COPY
ssh -i instance.pem ubuntu@<IP_ADDRESS>
Configuring Ubuntu on Remote VM
Once connected to the instance, let's configure Ubuntu on the remote VM.
- Update the outdated packages and dependencies:
COPY
sudo apt update
Install Git: Guide by DigitalOcean
Configure Node.js and npm: Guide by DigitalOcean
Deploying the Project on AWS
Now that our EC2 instance is set up, let's deploy our project on AWS.
- Clone the project in the remote VM:
COPY
git clone https://github.com/verma-kunal/AWS-Session.git
- Set up the environment variables in a
.env
file:
COPY
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""
For this project, we'll have to set up an Elastic IP Address for our EC2, which will be our DOMAIN
.
- Initialise and start the project:
COPY
npm install
npm run start
Note: We will have to edit the inbound rules in the security group of our EC2 to allow traffic from our particular port.
Project is Deployed on AWS ๐
Our Node.js application is now deployed on AWS EC2!
Subscribe to my newsletter
Read articles from Pratik Gote directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Pratik Gote
Pratik Gote
About Me ๐ Greetings! I'm Pratik Gote, a dedicated software developer with a strong passion for staying at the forefront of technological advancements in the industry. Armed with a solid foundation in Computer Science, I excel in creating innovative solutions that push boundaries and deliver tangible results. What I Do I specialize in: Full-Stack Development: Crafting scalable applications using cutting-edge frameworks such as React, Vue.js, Node.js, and Django. ๐ป Cloud Computing: Harnessing the capabilities of AWS, Azure, and Google Cloud to architect and deploy robust cloud-based solutions. โ๏ธ DevOps: Implementing CI/CD pipelines, Docker containerization, and Kubernetes orchestration to streamline development workflows. ๐ง AI and Machine Learning: Exploring the realms of artificial intelligence to develop intelligent applications that redefine user experiences. ๐ค My Passion Technology is dynamic, and my commitment to continuous learning drives me to share insights and demystify complex concepts through my blog. I strive to: Demystify Emerging Technologies: Simplify intricate ideas into accessible content. ๐ Share Practical Insights: Offer real-world examples and tutorials on state-of-the-art tools and methodologies. ๐ ๏ธ Engage with Fellow Enthusiasts: Foster a collaborative environment where innovation thrives. ๐ค Get in Touch I enjoy connecting with like-minded professionals and enthusiasts. Let's collaborate on shaping the future of technology together! Feel free to connect with me on LinkedIn : https://www.linkedin.com/in/pratik-gote-516b361b3/ or drop me an email at pratikgote69@gmail.com. Let's explore new horizons in technology! ๐