VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-os-platform-method/

⇱ Node.js os.platform() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js os.platform() Method

Last Updated : 28 Apr, 2025

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

Syntax:  

os.platform()

Parameters: This method does not accept any parameters.

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

Example 1: The below example illustrates the use of the os.platform() method in Node.js:

Output:  

linux

Example 2: The below example illustrates the use of the os.platform() method in Node.js:

Output:  

linux

Example 3: The below example illustrates the use of os.platform() method in Node.js:

Output:  

Linux Platform

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

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

Comment

Explore