Q:

How do I determine the current operating system with Node.js

I'm writing a couple of node shell scripts for use when developing on a platform. We have both Mac and Windows developers. Is there a variable I can check for in Node to run a .sh file in one instance and .bat in another?

A:

The variable to use would be process.platform
On Mac the variable returns darwin. On Windows, it returns win32 (even on 64 bit).
Current possible values are:

aix
darwin
freebsd
linux
openbsd
sunos
win32

I just set this at the top of my jakeFile:
var isWin = process.platform === "win32";

A:

With Node.js v6 (and above) there is a dedicated os module, which provides a number of operating system-related utility methods.
On my Windows 10 machine it reports the following:
var os = require('os');

console.log(os.type()); // "Windows_NT"
console.log(os.release()); // "10.0.14393"
console.log(os.platform()); // "win32"

You can read it's full documentation here: https://nodejs.org/api/os.html#os_os_type

A:

You are looking for the OS native module for Node.js:
v4: https://nodejs.org/dist/latest-v4.x/docs/api/os.html#os_os_platform
or v5 : https://nodejs.org/dist/latest-v5.x/docs/api/os.html#os_os_platform

os.platform()
Returns the operating system platform. Possible values are 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'. Returns the value of process.platform.

