npm run and npx — running tools without installing them globally¶
Level: 101 · for anyone who has run npm test
Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.
One line: npm run puts node_modules/.bin first on PATH — the package's own and every parent folder's — so a script can call tsc by name; npx tsc outside a TypeScript project would fetch the package named tsc, a deprecated 2.0.4 release, which npx --no refuses.
Keywords: npm run, npx, node_modules/.bin, npm_lifecycle_event
What the finished page will answer¶
- Which folders does
npm runput in front ofPATH, and in what order? - How does
npm run build -- --watchpass--watchto the script, and what donpm_lifecycle_eventandnpm_package_namehold inside it? - What does
npx tsc --versionprint inside the repo, and what doesnpx --no tscsay in an empty folder? - Where does
npxkeep a package it downloads, and what does--package=typescriptchange? - Which script names run without
run, such asnpm test, and when dopretestandposttestrun?
Examples it will need¶
-
npm_scripts_path_sh.sh— the first PATH entries insidenpm runfor a package two folders deep -
npm_scripts_arguments_and_env_sh.sh—npm runpassing arguments after--, and the npm_lifecycle_event and npm_package_name a script sees -
npx_inside_and_outside_a_project_sh.sh—npx --no tsc --versionin the repo (7.0.2), then in an empty folder with a fresh cache: the refusal naming tsc@2.0.4
See also¶
- npm — where
scriptsanddevDependenciesare declared tscandtsconfig.json— thetsca script should find- The built-in test runner —
npm testrunningnode --test process— thenpm_variables arrive inprocess.env- Rust: Cargo subcommands worth knowing ↗ — subcommands in Cargo, the nearest thing to npm scripts