Search code examples
node.jsmacosoperating-systemdarwin

os.platform() returns darwin instead of OSX


os.platform();

The above JS instruction returns the name of OS .

  • When it is runned on Ubuntu , it returns

    'linux'
    
  • When it is runned on Macbook, it returns

    'darwin'
    

I am wondered why does not return osx ,unix or bsd.. ?

Does darwinis a fork of osx ?

How to get the type of OS under MAC using Node.js ?


Solution

  • Darwin is not OSX, OSX is Darwin.

    Darwin is the core of OSX, in the same way, Linux is the core of Debian, Ubuntu, and every other Linux distributions.

    So while you can be 100% sure that any Apple product (macOS, OSX, iOS, watchOS, tvOS) will return Darwin, it is technically not correct to assume that darwin will only ever be thoses OSs, since some low profile open source projects exists, like PureDarwin, and thoses would also return darwin.

    However, I do not know of any (officials) port of node.js for any other Darwin-based OSs than OSX, so in practice, yes, if you get darwin, you can be confident it is OSX.