Deploy Node js API on AWS EC2 Instance
Great for testing simple deployments on Cloud, VPS
Install node version manager (nvm) by typing the following at the command line.
sudo su -
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bashActivate nvm by typing the following at the command line.
. ~/.nvm/nvm.shUse nvm to install the latest version of Node.js by typing the following at the command line.
nvm install nodeTest that node and npm are installed and running correctly by typing the following at the terminal:
node -v
npm -vTo install git, run below commands in the terminal window:
sudo apt-get update -y
sudo apt-get install git -yor
sudo yum update -y
sudo yum install git -yJust to verify if system has git installed or not, please run below command in terminal:
git --versionThis command will print the git version in the terminal.
Run below command to clone the code repository from Github:
git clone https://github.com/dmhaui/ocr-eop.gitGet inside the directory and Install Packages
cd ocr-eop
npm installStart the application To start the application, run the below command in the terminal:
npm startNow, we will need to run the api 24/24 even when the EC2 console is closed
When you close the console tab in web view, even though the instance is still running, the code will not function properly
PM2 will help us continue running our code even after the terminal is closed
Install PM2 by typing the following at the command line.
npm install pm2 -g && pm2 updatepm2 start app.js: Start a Node.js application.
pm2 stop app: Stop a running application.
pm2 restart app: Restart an application.
pm2 list: List all running processes.
pm2 monit: Display a monitoring interface for all running processes.
pm2 logs: View logs of running processes.
pm2 delete app: Remove a process from PM2.
pm2 start server.jspm2 listWe will see our server.js file displayed in a table.
pm2 stop 0