NodeJS (Version 22) – Ubuntu 22.04
Overview
Category: Frameworks
Supported OS: Ubuntu 22.04
NodeJS is a lightweight platform ideal for building fast, scalable network applications in JavaScript. Built on Chrome's JavaScript runtime, it is particularly suitable for data-intensive applications that operate across distributed devices. NodeJS offers an event-driven architecture similar to Ruby's Event Machine or Python's Twisted.
Software Included
- NodeJS: 22
- NPM: 9.3.1
- Nginx: 1.18.0
- PM2: 5.2.2
Getting Started After Deployment
1. Firewall Configuration
Allow only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) access for security and application access.
2. Deployment Message
During deployment, you will be logged out and see the following message:
Please wait until the installation is completed.... Connection to $IPADDRESS closed.
Do not log in for at least 2 minutes after the instance is created to allow the setup to complete.
3. First Login Steps
-
Log in as the
ubuntu
user, using your set password or SSH key. -
Switch to the
root
user without a password:sudo su -
-
NodeJS shell user login credentials are stored under:
/root/.shell_user_passwords
-
NodeJS home directory:
/var/www/html/
-
NodeJS PM2 files are stored under:
/home/nodejs/
4. Managing NodeJS Applications
-
The default sample app is located at
/var/www/html/hello.js
. You can modify this script and see changes live using PM2, the process manager that schedules your code to run at boot time. Applications run as thenodejs
user. -
To restart the sample app after making changes:
sudo -u nodejs pm2 restart hello
-
To deploy your own code, clone your repository or upload files to the instance. Change to the directory containing your NodeJS code and install dependencies:
npm install
-
Launch your app with PM2:
sudo -u nodejs pm2 start
<your-file>
5. Configuring Nginx as a Reverse Proxy
-
Edit the Nginx configuration to map your NodeJS app's port to an HTTP URL:
nano /etc/nginx/sites-available/default
-
Modify the entry exposing the sample app on port 3000 to your app’s port.
-
Restart Nginx to apply the changes:
sudo systemctl restart nginx
6. Scheduling Applications to Run at Boot
-
Save your current PM2 process list:
sudo -u nodejs pm2 save
-
Repeat the above steps for any additional NodeJS apps that should run concurrently.
-
To remove the sample app and stop it from running at boot:
sudo -u nodejs pm2 delete hello sudo -u nodejs pm2 save