NodeJS How to determine or check for current OS (Operating System)

There are two ways of doing it,

First using the native OS module,

Check out the API function available for OS module here

https://nodejs.org/dist/latest-v5.x/docs/api/os.html#os_os_platform 

Basically, all you have to do is to call platform() function from the OS class. Here is how its done

Check if its windows operating system,

os.platform()

Returns the operating system platform. Possible values are,'darwin' 'freebsd''linux''sunos' or.'win32'

A bit detailed code version with some other methods from my Windows 10 machine

Second, using the process’s platform property,

os.platform() basically returns the values of process.platform property

Above logic can be rewritten as

I hope this helps

Jas

VN:R_U [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:R_U [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Reply