How to get the hostname of the OS in Node.js?

Published March 21, 2021

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

Feel free to share if you found this useful 😃.

Share on: Facebook Twitter