Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.process 应用 #9

Open
Zijue opened this issue Feb 17, 2021 · 0 comments
Open

2.process 应用 #9

Zijue opened this issue Feb 17, 2021 · 0 comments
Labels

Comments

@Zijue
Copy link
Owner

Zijue commented Feb 17, 2021

全局变量

  • 概念:全局上可以直接访问的属性
  • 所有模块都可以直接访问到以下 5 个变量,但是它们并不是 global 上的属性
    • __dirname 绝对路径,指代的是当前文件所在的目录
    • __filename 绝对路径,指代的是当前文件的路径
    • exports
    • module
    • require()

global 中比较重要的属性

  • setTimeoutqueueMicrotasksetImmediate
  • process 代表进程,可以获得运行时一些环境和参数
  • Buffer 二进制数据容器,用于处理二进制数据;主要用于文件操作

process 中的重要属性

  • platform 代码运行的平台(win32 => windows,darwin => mac);每个平台找一些用户文件,位置可能不一样
  • cwd 当前工作目录(current working directory),运行时产生的一个路径,指向在哪里执行(可以改变)。相对路径相对的是工作目录,不是当前文件所在的目录。如果是一个确定的路径应使用绝对路径
  • chdir 切换当前工作目录
  • env 默认会读取全局的环境变量(也可以临时设置变量) npm install cross-env -g 全局安装 cross-env 设置临时的代码执行环境变量
  • argv 用户执行时传递的参数;可以使用优秀的命令行管家解析命令行参数 npm install commander
  • process.nextTick
@Zijue Zijue added the node.js label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant