本文介绍了如何使用Node.js确定当前的操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写几个节点外壳脚本,供在平台上开发时使用.我们有Mac和Windows开发人员.是否可以在Node中检查变量以在一个实例中运行.sh文件,在另一个实例中运行.bat?

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?

推荐答案

要使用的变量为 process.platform

The variable to use would be process.platform

在Mac上,变量返回darwin.在Windows上,它返回win32(即使在64位上).

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

当前可能的值是:

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

我只是将其设置在我的jakeFile的顶部:

I just set this at the top of my jakeFile:

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

这篇关于如何使用Node.js确定当前的操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 11:53