How to setup NodeJs in AWS ubuntu

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
  • Run sudo apt-get update
  • Run sudo apt install nodejs. This will install the latest available node environment
  • You can check the success of the installation process by running node -v. 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 then the 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 by SCP or by SFTP.
  • Now all you have to do is run 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 do pm2 stop app.js to stop executing the application.
  • If you want to get a list of all the running PM2 processes, you can do so by running pm2 ls . It will give you output like this –

And that’s it. You are done.

Leave a Reply

Your email address will not be published. Required fields are marked *