node --version
パッケージと実行環境
書き方
node --version | node -vPATHの先頭で見つかる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