Mauvis Ledford Mauvis Ledford - 1 year ago 136
Node.js Question

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?

Answer Source

The variable to use would be process.platform

On Mac the variable returns darwin. On Windows, it returns win32 (even on 64 bit).

Possible values are: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'

I just set this at the top of my jakeFile:

var isWin = /^win/.test(process.platform);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download