Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine the current operating system with Node.js

Tags:

node.js

I'm writing a couple of node shell scripts for use when developing on a platform. We have both Mac and Windows developers. Is there a variable I can check for in Node to run a .sh file in one instance and .bat in another?

like image 875
Mauvis Ledford Avatar asked Dec 30 '11 20:12

Mauvis Ledford


People also ask

What is OS in node JS?

OS is a node module used to provide information about the computer operating system. Advantages: It provides functions to interact with the operating system. It provides the hostname of the operating system and returns the amount of free system memory in bytes.

What is the current version of node JS?

js v18 is the Current version! Node. js 18 will be the 'Current' release for the next 6 months and then promoted to Long-term Support (LTS) in October 2022.


1 Answers

The variable to use would be process.platform

On Mac the variable is set to darwin. On Windows, it is set to win32 (even on 64 bit).

Current possible values are:

  • aix
  • darwin
  • freebsd
  • linux
  • openbsd
  • sunos
  • win32
  • android (Experimental, according to the link)

I just set this at the top of my jakeFile:

var isWin = process.platform === "win32"; 
like image 128
Mauvis Ledford Avatar answered Sep 18 '22 22:09

Mauvis Ledford