- 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.version() Method
The os module of Node.js provides a bunch of operating system-related utility methods and properties.
The Node.js os.version() method will return a string that represents the kernel version of the current operating system. Whereas on POSIX systems, the operating system release is specified by calling with a command named uname. On Windows, if the RtlGetVersion() is not available, GetVersionExW() will be used.
Syntax
Following is the syntax of the Node.js os.version() method −
os.version()
Parameters
This method does not accept any parameters.
Return value
This method returns a string that specifies the kernel version of the current operating system.
Example
In the following example, we are trying to print the kernel version of the current operating system by using the Node.js os.version() method.
const os = require('os'); console.log(os.version());
Error
/home/cg/root/63a002c52763b/main.js:3 console.log(os.version()); ^ TypeError: os.version is not a function at Object.<anonymous> (/home/cg/root/63a002c52763b/main.js:3:16) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Note − To get the accurate result, better execute the above code in local.
After executing the above program, the os.verison() method returns the kernel version of the current operating system.
Windows 10 Pro
Example
In this example, we are trying to implement another way to print the kernel version of the current operating system.
const os = require('os'); var version = os.version(); var curr_sys_ver = 'Windows 10 Pro'; if (version == curr_sys_ver){ console.log('The Version of current system is: ' + version); }
Output
home/cg/root/63a002c52763b/main.js:3 var version = os.version(); ^ TypeError: os.version is not a function at Object.<anonymous> (/home/cg/root/63a002c52763b/main.js:3:18) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Note − To get the accurate result, better execute the above code in local.
If we compile and run the above program, the os.verison() method returns the kernel version of the current system.
The Version of current system is: Windows 10 Pro