3

There are questions about OS version on the Stack Overflow but not about the Windows name, I am looking to find out Windows name using Node.js.

I have looked into so many modules like os, platform, getos and using process etc. and found that these are helpful to get operating system description, process environment etc. I am able to get it is Linux or Windows too i.e. which platform I am using.

But, how can I check, is it Windows 7 or 8 which is installed on my system using Node.js?

I am using kinect2 module in my Node.js project which is working fine on Windows 8 but I am looking to use it on Windows 7.

I have checked that Kinect2 will not work with Windows 7.

halfer
  • 19,824
  • 17
  • 99
  • 186
Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75
  • 2
    Possible duplicate of [Node.js to get/determine OS version](http://stackoverflow.com/questions/14989081/node-js-to-get-determine-os-version) – Arman Yeghiazaryan Mar 01 '17 at 06:57

4 Answers4

14

Use os.release().

> os.release();
'10.0.18363'

On Windows, the result is in the form major.minor.build

Consult this table (source) to determine the version of Windows:

 Version                                    major.minor   
------------------------------------------ ------------- 
 Windows 10, Windows Server 2016            10.0
 Windows 8.1, Windows Server 2012 R2        6.3
 Windows 8, Windows Server 2012             6.2
 Windows 7, Windows Server 2008 R2          6.1
 Windows Vista, Windows Server 2008         6.0
 Windows XP Professional x64 Edition,       5.2
 Windows Server 2003, Windows Home Server
 Windows XP                                 5.1
 Windows 2000                               5.0

For Windows 10 specifically, consult this table (source) to determine the exact version:

 Version           build
----------------- -------
 Windows 10 1909   18363
 Windows 10 1903   18362
 Windows 10 1809   17763
 Windows 10 1803   17134
 Windows 10 1709   16299
 Windows 10 1703   15063
 Windows 10 1607   14393
 Windows 10 1511   10586
 Windows 10 1507   10240
MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
  • Hi, how could I detect if the platform is Windows Server 2016 or Windows 10, without using the build number? – Eghes Sep 06 '19 at 09:28
  • @Eghes I'm not sure if that is possible from Node.js APIs. You'll probably have to run a Windows command to get the Windows edition, with `child_process.exec()`, for example `wmic os get caption`, and parse the output. – MultiplyByZer0 Sep 06 '19 at 10:11
5

You can find the Windows version from the command line using ver. For example, on my machine:

>  ver

Microsoft Windows [Version 10.0.14393]

To execute this from node, use the child_process.execSync method:

var versionString = require('child_process').execSync('ver').toString().trim()

The whole .toString().trim() business is because the raw output from the command comes back as a Buffer, with newlines at the beginning and end.

rossipedia
  • 56,800
  • 10
  • 90
  • 93
  • 1
    I have edited answer. using this I can get window name but I am not looking for Jugaad ( don't know what to call jugaad in english ^_^ ). I am looking for standard code. – Deep Kakkar Mar 01 '17 at 10:35
  • From what I know, there is no node-specific API that will return a specific version of the operating system it is running on. You will have to resort to calling into OS specific APIs (such as `ver` on Windows, and `uname` on Linux) to get details about the OS – rossipedia Mar 01 '17 at 16:56
  • @DeepKakkar in terms of programming, "jugaad" can be loosely translated as hack – sid-m Nov 29 '17 at 10:24
  • in git bash for Windows 7 this returns `MINGW64_NT-6.1` – John Vandivier Feb 20 '19 at 19:23
1

FYI, os.release() will also return 10.x.x in win11, which still remains unsolved

interyang
  • 31
  • 3
-1
var os = require('os');
console.log(os.type());

refer to this link for more references: https://millermedeiros.github.io/mdoc/examples/node_api/doc/os.html

The other alternative can be the npm library : "platform"

check this out: https://www.npmjs.com/package/platform

Krisalay
  • 75
  • 3
  • 9