Search code examples
javascriptnode.jskinectnode-moduleskinect-v2

How to get Windows version using Node.js?


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.


Solution

  • 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.