如何确定当前操作系统是否是带有Node.js的Window 7

时间:2019-02-20 20:00:43

标签: node.js windows windows-7

我已经审查了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());

1 个答案:

答案 0 :(得分:-1)

给出:

  1. 项目中的所有开发人员都使用Windows 10或Windows 7。
  2. 项目中的所有Windows开发人员都使用Git Bash,因此I can't trust the otherwise nice require('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,但就我的用例而言,后一种情况将永远不会发生。

相关问题