To get the name or hostname of the OS, you can use the hostname() method from the os module in Node.js.
/* Get hostname of os in Node.js */
// import os module
const os = require("os");
// get host name
const hostName = os.hostname();
- The method returns the name of the system where the OS currently is installed as a
string.
See the above code live in repl.it.