5 ms·
What is the use case for NPM run?
Why should I use `npm run`? I can do the same with `node my-script.js` — the script starts faster and I can see more clearly what I'm doing. I can see only benefits for not using npm run.
Same question obviously applies to pnpm and bun too.
Thanks!!
- tipiirai 3y agoOne rationale is this "You can reduce complex node-related shell scripts into simple one-liners". But I can also do that with my own script and make the one-liner even simpler. ie `node deploy` is simpler than `npm run deploy`. I can even just run `deploy.js` with a shebang.
- dingosity 3y agoI think it's used so you can easily run a command using the same environment other npm commands run under. https://docs.npmjs.com/cli/v10/commands/npm-run-script https://docs.npmjs.com/cli/v10/commands/npm-run-script Which is to say... I think you can do everything the `npm run <foo>` command does from the command line, but it would require typing a lot more characters. You would have to do something like this to get what running `npm run` does automagically: NODE_PATH=./node_modules/.bin node -r ./node_modules/env foo.js which is more characters to type than npm foo