DEV Community

Cover image for Deploying A Simple Nodejs App on AWS
Christiana
Christiana

Posted on

Deploying A Simple Nodejs App on AWS

Introduction

In this project, we will deploy a simple Node.js application on AWS. AWS provides a Scalable and secure platform for hosting web applications, and Node.js is a popular JavaScript runtime for building server-side applications. By deploying our Node.js app on AWS, we will leverage the benefits of cloud computing, including scalability, reliability, and cost-effectiveness. So, let's dive in 😊

Step 1: Creating EC2 instance

  • Go to your AWS Management Console and search for EC2
  • Click on it
  • Click on launch instance
  • Name your instance
  • Let's work with Ubuntu
  • Choose free tier
  • Create key pair (choose pem)
  • Launch your instance

Step 2: Connecting our EC2

  • After creating the EC2, connect it with any terminal of your choice
  • After connecting, type sudo apt update
  • After updating, type sudo apt install git -y
  • After installing git, check the version by typing git --version
  • Type sudo apt install nodejs -y
  • After installing nodejs, type node -v (for version)
  • Type sudo apt install npm -y
  • After installing npm, type git clone and paste this GitHub repo URL project repo
  • Type ls

  • Cd to AWS-node-js-app-deployment
  • Type touch .env (to create an env file)
  • Type vi .env (to open the file)
  • press your esc button and press i
  • Go to the GitHub repo, scroll down and copy the .env command you see
  • Paste it in the vi file
  • Then press your esc button and type :wq! (To save and quit)

Step 3: Getting Stripe API key

  • Go to your browser and search stripe

- Click on create account

  • Fill in the form
  • After creating the account, click on more below

  • Click on developers
  • Click on API keys
  • copy the publishable key and secret key, paste it in your notepad

  • Go back to your terminal
  • Type vi .env
  • press your esc button and press i
  • Paste the publishable key where you see publishable key, and paste the secret key where you see secret key

  • Type :wq! (Save and quit)

  • Type cat .env (to view the content of your file)
  • Type npm install
  • Type npm start

Step 4: Setting security

  • Go to your AWS EC2 instance
  • Click on the instance
  • Click on security
  • Click on sg-0
  • Click on edit inbound rules
  • Click on Add rule
  • Under type, choose custom TCP
  • Under port range, put 3000 ( or any port of your choice)
  • Choose anywhere
  • Save

Step 5: Testing our Nodejs App

  • Copy your EC2 public IP
  • Go to your browser
  • Paste the IP:3000

Please try this steps and give me a feedback.
See you soon...

Top comments (0)