Node.js | os.type() Method

The os.type() method is an inbuilt application programming interface of the os module which is used to get Operating system name.
Syntax:

os.type()

Parameters: This method does not accept any parameters.
Return Value: This method returns a string that represents operating system name. The returned value can be one of these ‘Darwin’ for MacOS, ‘Linux’ for Linux and ‘Windows_NT’ for windows.
Below examples illustrate the use of os.type() method in Node.js:

Example 1:

javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// os.type() method 
     
// Allocating os module
const os = require('os');
  
// Printing os.type() value
console.log(os.type());

chevron_right


Output: 

Windows_NT

Example 2:

javascript



filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// os.type() method 
     
// Allocating os module
const os = require('os');
  
// Printing os.type() value
var type = os.type();
switch(type) {
    case 'Darwin':
        console.log("MacOS");
        break;
    case 'Linux'
        console.log("Linux operating system");
        break;
    case 'Windows_NT':
        console.log("windows operating system");
        break;    
    default
        console.log("other operating system");
}

chevron_right


Output:

windows operating system

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/os.html#os_os_type




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.