Why does showing npm version command takes more than 1 second? what does it do under the hood?
The command I run on my MacOS:
$ npm -v
8.15.0
Version: Monterey 12.6.1 (21G217)
Updated Feb 15
npm is a symlink to npm-cli.js and npm-cli.js only contains 2 lines of code. So the question is:
Why the 2 lines of code is so slow?
$ cat /usr/local/lib/node_modules/npm/bin/npm-cli.js
#!/usr/bin/env node
require('../lib/cli.js')(process)
$ which npm
/usr/local/bin/npm
$ll /usr/local/bin/npm
lrwxr-xr-x 1 root wheel 38 Sep 28 12:03 /usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js