
Deploying a Node.js application on cloud platforms like Heroku, AWS EC2, and DigitalOcean ensures scalability, high availability, and efficient resource management. In this guide, we will explore the deployment process for each of these platforms.
1. Deploying on Heroku
Heroku is a Platform-as-a-Service (PaaS) that makes it easy to deploy and manage applications.
Steps to Deploy:
Install Heroku CLI: Download and install the Heroku CLI from Heroku’s website.
Login to Heroku: Run the following command:
heroku login
Initialize a Git Repository:
git init
heroku create my-node-app
Add a Procfile to the root directory: This file defines the process to start the application.
web: node server.js
Deploy the Application:
git add .
git commit -m “Deploy to Heroku”
git push heroku main
Access the Deployed App:
heroku open
2. Deploying on AWS EC2
Amazon EC2 provides scalable virtual servers in the cloud.
Steps to Deploy:
Create an EC2 Instance:
Sign in to AWS Console.
Launch a new EC2 instance with an Ubuntu or Amazon Linux AMI.
Connect to the Instance: Use SSH to access your server.
ssh -i your-key.pem ec2-user@your-ec2-ip
Install Node.js and Git:
sudo apt update
sudo apt install -y nodejs npm git
Clone Your Project and Install Dependencies:
git clone https://github.com/your-repo.git
cd your-project
npm install
Run the Application:
node server.js
Use PM2 to Keep the Application Running:
npm install -g pm2
pm2 start server.js
Set Up a Reverse Proxy with Nginx (Optional):
sudo apt install nginx
sudo nano /etc/nginx/sites-available/default
Add the following configuration:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection ‘upgrade’;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Restart Nginx:
sudo systemctl restart nginx
3. Deploying on DigitalOcean
DigitalOcean provides cloud computing solutions tailored for developers.
Steps to Deploy:
Create a Droplet:
Choose an Ubuntu-based droplet.
Access the Droplet via SSH:
ssh root@your-droplet-ip
Install Node.js and PM2:
sudo apt update
sudo apt install -y nodejs npm
npm install -g pm2
Clone the Repository and Install Dependencies:
git clone https://github.com/your-repo.git
cd your-project
npm install
Start the Application with PM2:
pm2 start server.js
pm2 save
Set Up Nginx as a Reverse Proxy:
sudo apt install nginx
sudo nano /etc/nginx/sites-available/default
Configure Nginx as shown in the AWS EC2 section and restart the service.
Conclusion
Deploying Node.js applications on cloud platforms provides flexibility and scalability. Heroku offers ease of deployment, AWS EC2 provides customization, and DigitalOcean is developer-friendly. Choose a platform based on your project needs and budget.
If you are looking for any services related to Website Development, App Development, Digital Marketing and SEO, just email us atย nchouksey@manifestinfotech.comย or Skype id:ย live:76bad32bff24d30d
๐ ๐จ๐ฅ๐ฅ๐จ๐ฐ ๐๐ฌ:
๐๐ข๐ง๐ค๐๐๐ข๐ง:ย linkedin.com/company/manifestinfotech
๐ ๐๐๐๐๐จ๐จ๐ค:ย facebook.com/manifestinfotech/
๐๐ง๐ฌ๐ญ๐๐ ๐ซ๐๐ฆ:ย instagram.com/manifestinfotech/
๐๐ฐ๐ข๐ญ๐ญ๐๐ซ:ย twitter.com/Manifest_info
#NodeJS #CloudComputing #AWS #Heroku #DigitalOcean #WebHosting #Deployment