Day 29: Deploying nodejs application on AWS EC2

Day 29: Deploying nodejs application on AWS EC2

#90daysofdevops

🚀Introduction

Today in this blog, we will deploy a Node.js app on AWS. The blog provides a step-by-step guide on how to deploy the app. Let's elevate our Node.js app to the cloud and watch it shine in the digital firmament!


  1. First, you will need to create an EC2 instance on AWS and set up an SSH key pair for authentication. Once this is done, you can use an SSH client (such as the Terminal on MacOS or PuTTY on Windows) to connect to the EC2 instance.

  2. To update the outdated packages & dependencies type command :

    sudo apt update

  1. Install git if it is not installed. It will allow you to clone your remote repository. To install git type command sudo apt-get install git on your terminal. In my case, git was already installed, so I didn't need to install it again.

  2. Now install Node.js on your instance. It will manage dependencies using npm. To install nodejs on your instance use command sudo apt install nodejs. After successfully installing nodejs on your instance check version of nodejs by typing command node -v.

  3. Now we need to download npm (Node Package Manager) to manage packages. To download npm type command sudo apt install npm. After successfully installing npm on your instance check version of npm by typing npm -v

  4. Now clone the repository. To clone the repository use commad git clone <url>.

  5. After repository get cloned type command ls, suppose your file name is xyz then type command cd xyz. After getting file open set environment variable file.

    • Steps to set environment variable Type command touch .file_name it creates an empty file. We use dot(.) before file_name because it's making the file hidden in the directory.

    • This is often used for configuration files, like environment variable files, where you might not want them to be easily visible in directory listings.

    • To see hidden files in directory use command ls-a

    • Edit the file using command vim file_name in that file write the below-mentioned

    • To see what you have written in file use command cat file_name

        DOMAIN= " " 
        PORT=3000 
        STATIC_DIR="./client"
        PUBLISHABLE_KEY=" " 
        SECRET_KEY=" "
      
    • To see what you have written in file use command cat file_name

      To understand it better, take a look at the photo provided below.

Tip: To PUBLISHABLE_KEY & SECRET_KEY visit the website provided below create account after that click on developer after that click on API Keys in that you will get the keys.

To understand it better, take a look at the photo provided below.

Stripe API Keys

  1. Install npm again. First, we installed npm on the instance, and now we need to do it in the repository's folder. To install npm type command npm install.

  2. After successfully installing npm run npm by typing command npm run start

  3. Application will not run. To run the application you need to edit inbound rule to 3000 port in Security group.

  4. Now your application is ready to run copy your instance public IP address and paste it on Google or browser whatever you use and use (:) colon after pasting IP address and type port number. Ex- 39.637.378.0:3000


Summary

In this post we covers the steps required to deploy a Node.js application on AWS EC2.


Thanks for reading to the end; I hope you gained some knowledge.❤️🙌

Linkedln

Twitter

Github