- 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.platform() Method
The Node.js os.platform() method returns a string value that specifies the operating system platform of the system that compiled the Node.js binary. The possible output string values are 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', or 'win32'. The value 'android' may be returned when the Node.js binary is compiled on an Android device. However this 'Android' is an experimental phase in Node.js.
The process.platform property can also get the operating system platform of the current system.
Syntax
Following is the syntax of the Node.js os.platform() method −
os.platform()
Parameters
This method does not accept any parameters.
Return value
This method returns a string value that specifies the operating system platform of the system where the Node.js binary is compiled.
Example
In the following example, we are trying to get the operating system platform of the current system by using the Node.js os.platform() method.
const os = require('os'); console.log(os.platform());
Output
linux
Note − To get the accurate result, better execute the above code in local.
If we compile and run the above program, the os.platform() method returned the operating system platform
win32
Example
In the following example, we are trying to get the operating system platform of the current system by using the process.platform property of Node.js.
console.log(process.platform);
Output
linux
Note − To get the accurate result, better execute the above code in local.
After executing the above program, the process.platform property printed the operating system platform.
win32
Example
In the example below,
We are performing a switch case to get the operating system platform of the current system.
So the switch will check each case against the output string value of os.platform() method until a match is found.
If nothing matches, the default condition will be printed.
const os = require('os'); const Ope_sys_platform = os.platform() switch(Ope_sys_platform){ case 'aix': console.log('This is IBM AIX platform'); break; case 'darwin': console.log('This is Darwin platform'); break; case 'freebsd': console.log('This is FreeBSD Platform'); break; case 'linux': console.log('This is Linux Platform'); break; case 'openbsd': console.log('This is OpenBSD platform'); break; case 'sunos': console.log('This is SunOS platform'); break; case 'win32': console.log('This is windows platform'); break; case 'android': console.log('This is Android platform'); break; default: console.log('This is an Unknown platform'); }
Output
This is Linux Platform
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.platform() method will be 'win32'. So the case 'win32' got matched and executed.
This is windows platform
To Continue Learning Please Login
Login with Google