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 darwin
is a fork of osx ?
How to get the type of OS under MAC using Node.js ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With