-1

I have reviewed How do I determine the current operating system with Node.js, and similar posts, but have yet to find a solution.

I am using Docker on Windows 7. This situation is unique because under my setup I have to use my local IP when configuring webpack dev server proxy requests. This is different from other developers on the project using Windows 10 or Mac, who are able to proxy localhost.

This answer comes close, but conditionally checking isWindows is not good enough. I need to check isWindows7. I have tried these, but I don't see anything (AFAIK) good enough to prove that I am using 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());
John Vandivier
  • 2,158
  • 1
  • 17
  • 23

1 Answers1

-1

Given:

  1. All of the developers on my project use either Windows 10 or Windows 7.
  2. All Windows developers on my project use Git Bash, so I can't trust the otherwise nice require('child_process').execSync('ver').toString().trim().

Then for my use case, this is sufficient:

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

As shown in this answer, a release beginning in 6.1 could technically refer to Windows 7 or Windows Server 2008, but for my use case the latter scenario will never occur.

John Vandivier
  • 2,158
  • 1
  • 17
  • 23