Related Articles

Related Articles

Node.js | process.platform Property
  • Last Updated : 25 Feb, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);

chevron_right


Output:

win32

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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 platfrom(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");
}

chevron_right


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




My Personal Notes arrow_drop_up
Recommended Articles
Page :