node --version
套件與執行環境
用法
node --version | node -v印出 PATH 上第一個 node 的版本;正因如此,用了版本管理器時編輯器終端機或 CI 裡看到的常常是另一個版本。
常用選項
| 選項 | 含義 |
|---|---|
| -v | the 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 |
| --help | every flag this build accepts |
範例
node --versionthe version of the node first on your PATH
node -p process.execPathwhich binary that actually is, when several are installed
node -p process.versions.v8the 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