How to get Windows version using Node.js?

后端 未结 3 1452
栀梦
栀梦 2020-12-21 23:01

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

相关标签:
3条回答
  • 2020-12-21 23:15

    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
    
    0 讨论(0)
  • 2020-12-21 23:23
    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

    0 讨论(0)
  • 2020-12-21 23:30

    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.

    0 讨论(0)
提交回复
热议问题