Deploying a Node Js Application on AWS EC2

Testing the project locally

Clone this project on the local machine.

git clone https://github.com/SUBHAM-NANDI/AWS-Session.git

Open the project on VSCode.
Create an environment variable(.env) file.

touch .env

This wil…


This content originally appeared on DEV Community and was authored by Subham Nandi

Testing the project locally

  • Clone this project on the local machine.
git clone https://github.com/SUBHAM-NANDI/AWS-Session.git
  • Open the project on VSCode.

  • Create an environment variable(.env) file.

 touch .env

This will create a hidden .env file.

Environment variable files are essential for securely managing configuration settings and secrets across different environments (development, testing, production). They separate configuration from code, enhance security by preventing hardcoding of sensitive data, ensure consistency, simplify deployment, and support easy environment-specific configurations. This centralized management approach promotes maintainability and flexibility, making managing and updating settings easier without altering the codebase.

  • Setup the following environment variables - (.env) file
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"

PUBLISHABLE_KEY=""
SECRET_KEY=""

Create a Stripe account for free and copy the publishable and secret keys, respectively.
Document link - https://docs.stripe.com/keys

  • Initialise all dependencies and start the project
npm install 
npm run start

Set up an AWS EC2 instance

  • Create an IAM user & login to your AWS Console

    • Access Type - Password
    • Permissions - Admin
  • Create an EC2 instance

    • Select an OS image - Ubuntu
    • Create a new key pair & download .pem file
    • Instance type - t2.micro
  • Connecting to the instance using ssh

Open an SSH client.
Locate your private key file. The key used to launch this instance is node.js-app-deploy.pem
Run this command, if necessary, to ensure your key is not publicly viewable.
Change the permission of the .pem file using the below cmd.

chmod 400 "instance.pem"

Connect to the ec2 instance using the below cmd

ssh -i instance.pem ubunutu@<PUBLIC IP_ADDRESS>
  • Updating the outdated packages and dependencies
sudo apt update
sudo apt install git
sudo apt install nodejs
sudo apt install npm

Deploying the project on AWS

  • Clone this project in the remote VM
git clone https://github.com/SUBHAM-NANDI/AWS-Session.git
  • Create and open an environment variable(.env) file in the project folder.
touch .env
vim .env
  • Setup the following environment variables - (.env) file
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 & that would be our DOMAIN

  • Initialise and start the project
npm install
npm run start

NOTE - We will have to edit the inbound rules in the security group of our EC2, in order to allow traffic from our particular port
Go to the EC2 instance and go to security. Click on Security groups and then edit the Inbound Roules.
Add a separate Inbound rule with *Type - Custom TCP * and post range - 3000 and then save.

Project is deployed on AWS 🎉

IMPORTANT - THIS NODE.JS APP HAS BEEN TAKEN FROM SOMEWHERE ELSE.


This content originally appeared on DEV Community and was authored by Subham Nandi


Print Share Comment Cite Upload Translate Updates
APA

Subham Nandi | Sciencx (2024-07-30T20:11:17+00:00) Deploying a Node Js Application on AWS EC2. Retrieved from https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/

MLA
" » Deploying a Node Js Application on AWS EC2." Subham Nandi | Sciencx - Tuesday July 30, 2024, https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/
HARVARD
Subham Nandi | Sciencx Tuesday July 30, 2024 » Deploying a Node Js Application on AWS EC2., viewed ,<https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/>
VANCOUVER
Subham Nandi | Sciencx - » Deploying a Node Js Application on AWS EC2. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/
CHICAGO
" » Deploying a Node Js Application on AWS EC2." Subham Nandi | Sciencx - Accessed . https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/
IEEE
" » Deploying a Node Js Application on AWS EC2." Subham Nandi | Sciencx [Online]. Available: https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/. [Accessed: ]
rf:citation
» Deploying a Node Js Application on AWS EC2 | Subham Nandi | Sciencx | https://www.scien.cx/2024/07/30/deploying-a-node-js-application-on-aws-ec2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.