os.platform() returns darwin instead of OSX
Asked Answered
D

3

6
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 ?

Daley answered 26/7, 2016 at 14:36 Comment(0)
T
12

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.

Twibill answered 26/7, 2016 at 14:40 Comment(0)
W
4

Darwin is the underlying platform for OS X.

To get the OS X version instead, you can do this via the command line (or child process) with: defaults read loginwindow SystemVersionStampAsString or sw_vers -productVersion

To get the version via C/C++ (which you could write a binding for to access from node):

// compile with: g++ osx_ver.cc -I/Developer/Headers/FlatCarbon -framework CoreServices
#include <Gestalt.h>
#include <stdio.h>

int main() {
  SInt32 majorVersion, minorVersion, bugFixVersion;

  Gestalt(gestaltSystemVersionMajor, &majorVersion);
  Gestalt(gestaltSystemVersionMinor, &minorVersion);
  Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);

  printf("%d.%d.%d", majorVersion, minorVersion, bugFixVersion);

  return 0;
}

Note: The Gestalt() usage shown above is deprecated since OS X 10.8, but its replacement seemingly isn't available until OS X 10.10, so you may need to use Objective-C instead ([processInfo operatingSystemVersion]) and branch on API availability like what is done here in Chromium.

Waterfowl answered 26/7, 2016 at 14:48 Comment(0)
B
1

Darwin was the original name given to OS X by apple. It was named as such because it was the NeXT step in the evolution of operating systems.

Bigner answered 26/7, 2016 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.