【问题标题】:How do I determine if current operating system is Window 7 with Node.js如何确定当前操作系统是否为带有 Node.js 的 Window 7
【发布时间】:2019-07-14 14:47:44
【问题描述】:

我查看了How do I determine the current operating system with Node.js 和类似的帖子,但尚未找到解决方案。

我在 Windows 7 上使用 Docker。这种情况是独一无二的,因为在我的设置下,我必须在配置 webpack 开发服务器代理请求时使用我的本地 IP。这与项目中使用 Windows 10 或 Mac 的其他开发人员不同,他们能够代理 localhost。

This answer comes close,但是有条件地检查 isWindows 还不够好。我需要检查isWindows7。我已经尝试过这些,但我没有看到任何东西(AFAIK)足以证明我使用的是 Windows 7:

const os = require('os');
console.log(os.platform());
console.log(os.type());
console.log(os.release());
console.log(os.arch());
console.log(os.hostname());

【问题讨论】:

    标签: node.js windows windows-7


    【解决方案1】:

    给定:

    1. 我项目中的所有开发人员都使用 Windows 10 或 Windows 7。
    2. 我项目中的所有 Windows 开发人员都使用 Git Bash,所以I can't trust the otherwise nicerequire('child_process').execSync('ver').toString().trim()

    那么对于我的用例来说,这就足够了:

    const isWin7 = os.release().slice(0, 3) === '6.1';
    

    作为shown in this answer,从 6.1 开始的版本在技术上可能指的是 Windows 7 或 Windows Server 2008,但对于我的用例来说,后一种情况永远不会发生。

    【讨论】:

      猜你喜欢
      • 2012-01-30
      • 2011-01-07
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多