How to determine the current operating system with Node.js?

Sometimes, we want to determine the current operating system with Node.js.

In this article, we’ll look at how to determine the current operating system with Node.js.

How to determine the current operating system with Node.js?

To determine the current operating system with Node.js, we can use the process.platform property.

For instance, we write

const isWin = process.platform === "win32";

to check if the Node.js program is running on Windows.

All possible values for process.platform include:

  • aix
  • darwin
  • freebsd
  • linux
  • openbsd
  • sunos
  • win32
  • android

Conclusion

To determine the current operating system with Node.js, we can use the process.platform property.