Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *