Sometimes, we want to return hostname with Node.js and JavaScript.
In this article, we’ll look at how to return hostname with Node.js and JavaScript.
How to return hostname with Node.js and JavaScript?
To return hostname with Node.js and JavaScript, we use the os.hostname method.
For instance, we write
const os = require("os");
const hostname = os.hostname();
to call os.hostname to return a string with the hostname.
Conclusion
To return hostname with Node.js and JavaScript, we use the os.hostname method.