首页·终端命令

node --version

包与运行时

用法

node --version | node -v

打印 PATH 上第一个 node 的版本;正因如此,用了版本管理器时编辑器终端或 CI 里看到的常常是另一个版本。

常用选项

选项含义
-vthe same thing, shorter; prints e.g. v22.14.0
-p <expr>print one expression, e.g. node -p process.versions.v8
-e <code>run a line of code with no file
--env-file=<file>load a .env before running, from node 20.6
--helpevery flag this build accepts

示例

node --version

the version of the node first on your PATH

node -p process.execPath

which binary that actually is, when several are installed

node -p process.versions.v8

the V8 version bundled with it

问题永远是什么装到哪里:装进这个项目,还是装到整台机器上。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. node --version 是做什么的?

打印 PATH 上第一个 node 的版本;正因如此,用了版本管理器时编辑器终端或 CI 里看到的常常是另一个版本。

Q. 怎么写?

node --version | node -v —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man node。这条命令属于包与运行时。

相关命令

man 手册: man node---version