Reputation: 67474
I ran these commands and the output confused me:
$ npx node -v
Need to install the following packages:
[email protected]
$ node -v
v22.13.0
$ npm list | grep node
├── @rollup/[email protected]
├── @types/[email protected]
├── [email protected]
$ ls -a node_modules/.bin/node*
node_modules/.bin/node-which node_modules/.bin/node-which.cmd node_modules/.bin/node-which.ps1
These are the only dependencies in my package.json
that have node in their name, and I am not using the engine property:
"@rollup/plugin-node-resolve": "16.0.0",
"@types/node": "22.10.10",
"ts-node": "10.9.2",
Why do npx node -v
and node -v
return different versions?
I happen to be using cygwin, but type node
references the Windows install. I didn't find anything when I ran find / -maxdepth 3 -name 'node*' -type f -print
(root dir) or find . -name 'node*' -type f -print
(project dir). This makes me think the Windows install is the only node executable on my system.
This question looks very similar to node -v and nodejs -v shows different versions, but their question is asking about two different commands. I'm asking about the same command (node
) run directly on the CLI or run through npx
, that's the major difference.
Upvotes: -1
Views: 44
Reputation: 1
node -v
checks the globally installed Node.js version. This command directly runs node.js binary installed on system
npx node -v
might use a locally installed version of Node.js. This command runs actually from npm packages
Upvotes: -1