Node.js os.release() Method
The os.release() method is an inbuilt application programming interface of the os module which is used to get Operating system release.
Syntax:
os.release()
Parameters: This method does not accept any parameters.
Return Value: This method returns a string that represents operating system release.
Below examples illustrate the use of os.release() method in Node.js:
Example 1:
Javascript
// Node.js program to demonstrate the // os.release() method // Allocating os module const os = require( 'os' ); // Printing os.release() value console.log(os.release()); |
Output: On windows system
10.0.17763
Output: On Linux system
3.10.0-1062.1.1.el7.x86_64
Example 2:
Javascript
// Node.js program to demonstrate the // os.release() method // Allocating os module const os = require( 'os' ); // Printing os.platform() value var platform = os.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" ); } // Printing version console.log( "Version: " + os.release()); |
Output:
Windows platform Version: 10.0.17763
Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/api/os.html#os_os_release
Contact Us