Understanding difference between npx and npm

Viewed 56

I'm struggling to develop a deeper understanding of npx. So in particular the difference between running a commmand with npm and npx. I understand that npx can execute a package from a URL, just one local npm package etc.. But for example here:

npx lerna run start --scope frontend --stream

What is the difference between

npx lerna run start

and

npm lerna run start

?

1 Answers

NPM - Manages packages but doesn't make life easy executing any.

NPX - A tool for executing Node packages.

NPX comes bundled with NPM version 5.2+.

NPM by itself does not simply run any package. It doesn't run any package as a matter of fact. If you want to run a package using NPM, you must specify that package in your package.json file.

When executables are installed via NPM packages, NPM links to them:

1.local installs have "links" created at ./node_modules/.bin/ directory.

2.global installs have "links" created from the global bin/ directory (e.g. /usr/local/bin) on Linux or at %AppData%/npm on Windows.

Related