DEV Community

Cover image for How to get the hostname of the OS in Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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();
Enter fullscreen mode Exit fullscreen mode
  • 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.

Feel free to share if you found this useful 😃.


Top comments (0)