The os.hostname() method is an inbuilt application programming interface of the os module which is used to get host name of the operating system.
Parameters: This method does not accept any parameters.
Return Value: This method returns a string value that specifies the host name of the operating system.
Below examples illustrate the use of os.hostname() method in Node.js:
Hostname for the operating system is gekchos_lappy
Note: The above program will compile and run by using the
node index.js command.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.