- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js - os.type() Method
The Node.js os.type() method returns a string value that specifies the operating system type. For example, the returned string can be 'Linux' on Linux operating system, 'Darwin' on the mac operating system, and 'Windows_NT' on the windows operating system.
Syntax
Following is the syntax of the Node.js os.type() method −
os.type()
Parameters
This method does not accept any parameters.
Return value
This method returns a string that indicates the type of the operating system.
Example
In the following example, we are trying to return the type of the current operating system by logging the Node.js os.type() method to the console.
const os = require('os'); console.log(os.type());
Output
Linux
Note − To get the accurate result, better execute the above code in local.
After executing the above program, the os.type() method returned the type of the current operating system as shown in the output below.
Windows_NT
Example
In the example below,
We performed a switch case to get the type of the operating system.
So the switch checks each case against the output string value of the os.type() method until a match is found.
If nothing matches, the default condition will be printed.
const os = require('os'); const type_of_OS = os.type(); switch(type_of_OS) { case 'Linux': console.log("Hi, i'm Linux operating system. Ok bye"); break; case 'Darwin': console.log("Hi, i'm Darwin operating system. Ok bye"); break; case 'Windows_NT': console.log("Hi, i'm windows_NT operating system. Ok bye"); break; }
Output
Hi, i'm Linux operating system. Ok bye
Note − To get the accurate result, better execute the above code in local.
When we compile and run the above program, the output string value of the os.type() method will be 'Windows_NT'. So the case 'Windows_NT' got matched and executed.
Hi, i'm windows_NT operating system. Ok bye
To Continue Learning Please Login
Login with Google