A common follow-up to launching a CentOS or RHEL node is installing Node.js to run an application. Use the package source that matches your OS version and what your application needs. Skip the old Node.js 6.x setup scripts; they are obsolete.
Log into the node as root first. See Connect to a Linux node.
Check which Node.js stream your OS offers
Section titled “Check which Node.js stream your OS offers”dnf module list nodejsInstall Node.js and npm together
Section titled “Install Node.js and npm together”dnf install -y nodejs npmOn an older CentOS image that still uses yum, install with:
yum install -y nodejs npmCheck the Node.js and npm versions
Section titled “Check the Node.js and npm versions”node -vnpm -vConfirm the install with a small test server
Section titled “Confirm the install with a small test server”Create a file:
vim test_server.jsAdd this content:
const http = require("http");http .createServer((req, res) => { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Welcome"); }) .listen(3001, "127.0.0.1");console.log("Server running at http://127.0.0.1:3001/");Start it:
node test_server.jsYou see Server running at http://127.0.0.1:3001/, and visiting that address inside the node
returns Welcome. Node.js and npm are ready to use.
If a change here leaves the node unreachable, see Troubleshooting node networking and connectivity.