How to Install Node.js on AWS EC2 and Check Services Status

Introduction

Node.js is a tool that lets developers run JavaScript outside of a browser on the server. It’s fast, scalable, and designed to handle many tasks at once, making it great for real-time applications like chat apps or APIs. With Node.js, you can use JavaScript for both front-end and back-end development.

Here’s an overview of what we’ll cover.

  • Installing Node.js and npm (Node Package Manager).
  • Verifying the installation.
  • Checking and managing services on your EC2 instance.

How to Install Node.js on AWS EC2?

Step 1. Connect to Your EC2 Instance.

Before you begin, ensure that your EC2 instance is up and running. To connect to it, you’ll need to use SSH (Secure Shell) from your local terminal or PowerShell. Here's how,

  • Open a terminal or PowerShell on your local machine.
  • Use the ssh command to connect to your EC2 instance.
ssh -i "your-key.pem" ec2-user@<your-ec2-public-ip>

Login

Step 2. Installing Node.js on EC2.

Now that your EC2 instance is set up and you’re connected to it, the next step is to install Node.js. Node.js is a tool that helps you run JavaScript on the server, which is great for building applications like websites and APIs.

Before installing Node.js, it’s important to update the software on your EC2 instance to ensure everything works smoothly. Updating your system helps fix bugs and adds new features.

  1. Run this command to update your system.
    sudo apt update
  2. After the update is complete, it’s time to install Node.js. You can do this with just one simple command.
    sudo apt install nodejs
    Installation
  3. Here is the command to verify the installed version.
    node -v
    Latest version
  4. If you have a Node.js application running in the background, you can check its status by looking for the running Node.js processes.
  5. This command will show any processes related to Node.js, helping you confirm if your Node.js application is running.
    ps aux | grep node
    Running node
  6. Check specific Node.js applications (if you know the script name)
    ps aux | grep 'node app.js'
    Specific file
  7. Replace app.js with your specific script file.

In this article, we covered how to install Node.js on an AWS EC2 instance, enabling you to run JavaScript on the server side for scalable, real-time applications. With Node.js installed, you can easily manage processes and verify installations, setting you up for cloud-based development on EC2.


Similar Articles