node.js全局变量process

版权声明:本文为个人知识整理,欢迎指正、交流、转载。 https://blog.csdn.net/u014711094/article/details/80424173

process是node的一个全局变量,提供当前nodejs进程的信息。
- title version versions

title: '管理员:Windows PowerShell'
version: '8.9.1'

// node.js和dependencies的版本
versions: {
  http_parser: '2.7.0',
  node: '8.9.1',
  v8: '6.1.534.47',
  uv: '1.15.0',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',     // ABI version
  nghttp2: '1.25.0',
  openssl: '1.0.2m',
  icu: '59.1',
  unicode: '9.0',
  cldr: '31.0.1',
  tz: '2017b'
}
  • cwd(),当前工作目录(current working directory)
// g:\temp\src\a.js
console.log(process.cwd())
exports.x = 1

// g:\temp\index.js
const x = require('./a')

node index.js
// g:\temp
// 此时node.js进程在index.js所在的目录
  • argv argv0 execArgv execPath env
node --harmony g:\temp\index.js one two=three four

// 不包括node的options,第一个参数是execPath
argv: ['C:\\Program Files (x86)\\nodejs\\node.exe',
        'g:\\temp\\index.js',
        'one',
        'two=three',
        'four']

// node启动时,存储argv[0]的原始值(origin value),只读
argv0: 'C:\\Program Files (x86)\\nodejs\\node.exe'

// node命令的options
execArgv: ['--harmony']

// 启动node进程的可执行文件(executable)的绝对文件名
execPath: 'C:\\Program Files (x86)\\nodejs\\node.exe'

// 打印v8相关的options
node --v8-options 
  • platform arch env pid ppid
// 可能值:win32, sunos, linux, openbsd, freebsd, darwin, aix
platform: 'win32'

// 系统CPU架构(architecture), 可能:'ia32', 'x32', 'x64', 'arm', 'arm64'
arch: 'ia32'

// 当前系统环境变量
env: [path: '', ...]

// 进程id
pid: '10182'

// 父进程id
ppid: undefined

猜你喜欢

转载自blog.csdn.net/u014711094/article/details/80424173