Skip to content

Instantly share code, notes, and snippets.

@reygreen1
Last active May 20, 2019 05:20
Show Gist options
  • Save reygreen1/83a9d0f25448b22d2b7e to your computer and use it in GitHub Desktop.
Save reygreen1/83a9d0f25448b22d2b7e to your computer and use it in GitHub Desktop.
对node中全局对象的一些整理

##全局对象(global)

__dirname:当前文件所在目录的绝对路径

__filename:当前文件的绝对路径

console:输出信息

  1. console.log():打印日志信息
  2. console.info():打印相关信息
  3. console.error():打印错误信息
  4. console.warm():打印警告信息
  5. console.time():配合console.timeEnd()来统计程序执行时间

process:

  1. process.stdout:标准输出
  2. process.stderr:标准错误输出
  3. process.stdin:标准输入(使用前进行编码设置setEncoding)
  4. process.cwd():执行命令所在的目录路径
  5. process.on():监听事件,如data、readable、exit、SIGINT等
  6. process.exit():程序正常退出
  7. process.argv:获取命令执行时所输入的内容
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment