node.js - 如何确定当前操作系统是否为带有 Node.js 的 Window 7
问题描述
我已经查看了How do I determine the current operating system with Node.js和类似的帖子,但还没有找到解决方案。
我在 Windows 7 上使用 Docker。这种情况是独一无二的,因为在我的设置下,我必须在配置 webpack 开发服务器代理请求时使用我的本地 IP。这与项目中使用 Windows 10 或 Mac 的其他开发人员不同,他们能够代理 localhost。
这个答案很接近,但有条件地检查 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());
解决方案
鉴于:
- 我项目中的所有开发人员都使用 Windows 10 或 Windows 7。
- 我项目中的所有 Windows 开发人员都使用 Git Bash,所以我不能相信其他不错的
require('child_process').execSync('ver').toString().trim()
.
那么对于我的用例来说,这就足够了:
const isWin7 = os.release().slice(0, 3) === '6.1';
如这个答案所示,从 6.1 开始的版本在技术上可能指的是 Windows 7 或 Windows Server 2008,但对于我的用例,后一种情况永远不会发生。
推荐阅读
- vue.js - vue beforeRouteEnter 未被调用
- javascript - 如何使用 loadVirtual 和 ENOLOCK 修复 npm 审计错误?
- elasticsearch - 使用 filebeat 的多个分词器
- python - 当给定 ID 前面没有一组值或后面没有其他组值时,删除 df 行
- c# - 连接两个数组时 DynamicExpressionParser 不起作用
- powershell - cmd中的“wmic memorychip get | clip”
- python - 如何包含 Pyinstaller 在生成 .exe 期间无法导入的文件
- python - Youtube Data API V3 请求的身份验证范围不足(Python)
- sql - 在oracle中将列值转换为列
- reactjs - 在 React Native 中创建 InputField 组件时出错