Bootstrap FreeKB - Node.js - hostname
Node.js - hostname

Updated:   |  Node.js articles

os can be used to get the system hostname in Node.js. In this example, the full system hostname will be printed.

const os = require("os");
const hostname = os.hostname();
console.log(`hostname = ${hostname}`);

 

Be aware that if you are using a Node.js module instead of CommonJS, you will have "type": "module" in package.json. In this scenario, you will use import instead of require.

from os import "os";
const hostname = os.hostname();
console.log(`hostname = ${hostname}`);

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 7d5018 in the box below so that we can be sure you are a human.