Setting up node environment and deploying your node application is very easy in AWS EC2 instance. AWS provides multiple AMIs to chose from but in this post we will focus on Ubuntu 18.04 Linux machine to start with.
We will be needing following for a working AWS node environment –
- NodeJs environment
- PM2 – Process management tool
I’ll assume that the AWS EC2 instance with Ubuntu AMI is already up and running, if not do checkout How to setup AWS EC2 Ubuntu instance.
Now let’s begin by installing the Node environment.
- SSH into your instance
sudo apt-get update
sudo apt install nodejs.This will install the latest available node environment
- You can check the success of the installation process by
.It will show you the version installed in your instance
- Now let’s install PM2. PM2 will be used to execute your node run-time so that if you terminate your connection even
thenthe node process will continue to run.
- Now it’s time to make your node app up and running.
- If you don’t already have your node source code on the server, then make sure you have your latest code with all the required packages/plugins. You can get it done either by using a git repository or
- Now all you have to do is
pm2 start app.js
.This will start your node app considering app.js is the entry point. You can configure it according to your project structure.
- Similarly, you can
pm2 stop app.js
tostop executing the application.
- If you want to get a list of all the running PM2 processes, you can do so by
.It will give you output like this –
And that’s it. You are done.