How to get the name of the operating system platform in Node.js?

March 22, 2021 - 1 min read

To get the name of the operating system platform, you can use the platform() method from the os module in Node.js.

/* Get OS platform in Node.js */

// import os module
const os = require("os");

// get platform name
const platformName = os.platform(); // linux
  • The method returns the name of the operating system platform as a string.
  • There are 8 possible values that the method can return, those are:
    • linux
    • win32
    • darwin
    • aix
    • freebsd
    • openbsd
    • sunos
    • android (Experimental value)

See the above code live in repl.it.

Feel free to share if you found this useful 😃.