Need to migrate your e-mails to a new server? Free and paid versions of our online tool available.
Hero Image

Install Node.js on RHEL 9

Install Node.js on RHEL 9

Step 1 – Install

curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
dnf install -y nodejs

Step 2 – Verify

node --version && npm --version

Step 3 – Simple HTTP server

// app.js
const http = require('http');
http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello from Node.js!\n');
}).listen(3000, '127.0.0.1');
node app.js &
curl http://127.0.0.1:3000

Step 4 – systemd service

[Unit]
Description=My Node.js App
After=network.target
[Service]
User=nodejs
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node app.js
Restart=on-failure
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target

Step 5 – Nginx reverse proxy

location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
}