Open In App

Node.js process.platform Property

Last Updated : 12 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The process.platform property is an inbuilt application programming interface of the process module which is used to get the Operating System platform information.

Syntax:  

process.platform

Return Value: This property returns a string that represents the operating system platform. The returned value can be one of these ‘aix’, ‘android’, ‘darwin’, ‘freebsd’, ‘linux’, ‘openbsd’, ‘sunprocess’, and ‘win32’. This values is set at compile time.

Below examples illustrate the use of process.platform property in Node.js:

Example 1:  

Javascript




// Node.js program to demonstrate the
// process.platform Property
   
// Include process module
const process = require('process');
  
// Printing process.platform property value
console.log(process.platform);


Output: 

win32

Example 2: 

Javascript




// Node.js program to demonstrate the
// process.platform Property
   
// Include process module
const process = require('process');
  
// Printing process.platform property value
var platform = process.platform;
switch(platform) {
    case 'aix'
        console.log("IBM AIX platform");
        break;
    case 'darwin'
        console.log("Darwin platform(MacOS, IOS etc)");
        break;
    case 'freebsd'
        console.log("FreeBSD Platform");
        break;
    case 'linux'
        console.log("Linux Platform");
        break;
    case 'openbsd'
        console.log("OpenBSD platform");
        break;
    case 'sunos'
        console.log("SunOS platform");
        break;
    case 'win32':
        console.log("windows platform");
        break;    
    default
        console.log("unknown platform");
}


Output: 

windows platform

Note: The above program will compile and run by using the node filename.js command.
Reference: https://nodejs.org/api/process.html#process_process_platform
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads