Get the Operating system name or Platform name in NodeJS
Getting the operating system platform is very easy. In NodeJS at first, we just have to import a module ("os"
), which is a built-in module of NodeJs that provides several methods related to the operating system, some of the common functionalities provided by the os module are – operating system information, system-level information, path and directories, network interface, etc. To get the operating system name we can call methods like- platform()
or type()
. The syntax Looks like this-
const os = require("os"); console.log(os.platform()); console.log(os.type());
Here, for both the method, you will get the same results for Windows, you will get "Windows_NT"
, for Linux, you will get "Linux"
and for Mac, you will get "darwin"
.
The difference between the two methods is the platform()
provides more granular information compare to the other one and type()
is considered as reproved as it was of NodeJs V15 and is dejected. So it is better to use the platform()
method.
Leave a Reply