NPM - Manages packages but doesn't make life easy executing any.NPX - A tool for executing Node packages.
comes bundled withNPXversionNPM5.2+
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 NPM file.package.json
When executables are installed via NPM packages, NPM links to them:
./node_modules/.bin/ directory.bin/ directory (e.g. /usr/local/bin) on Linux or at %AppData%/npm on Windows.Documentation you should read
One might install a package locally on a certain project:
npm install some-package
Now let's say you want NodeJS to execute that package from the command line:
$ some-package
The above will fail. Only globally installed packages can be executed by typing their name only.
To fix this, and have it run, you must type the local path:
$ ./node_modules/.bin/some-package
You can technically run a locally installed package by editing your file and adding that package in the packages.json section:scripts
{
"name": "whatever",
"version": "1.0.0",
"scripts": {
"some-package": "some-package"
}
}
Then run the script using (or npm run-script):npm run
npm run some-package
will check whether npx exists in <command>, or in the local project binaries, and execute it. So, for the above example, if you wish to execute the locally-installed package $PATH all you need to do is type:some-package
npx some-package
Another major advantage of is the ability to execute a package which wasn't previously installed:npx
$ npx create-react-app my-app
The above example will generate a app boilerplate within the path the command had run in, and ensures that you always use the latest version of a generator or build tool without having to upgrade each time you’re about to use it.react
command may be helpful in the npx section of a script file,
when it is unwanted to define a dependency which might not be commonly used or any other reason:package.json
"scripts": {
"start": "npx gulp@3.9.1",
"serve": "npx http-server"
}
Call with: npm run serve
Apparently this is the new way npx behaves per github issue
Seems @jcollum ran across the very same issue per this stackoverflow question.
The dependencies of each of these commands are stored in a cache at , when I tried blowing all those away it worked..npm/_npx/*/node_modules
Finding which one to delete
ls ~/.npm/_npx/*/node_modules | grep matcha-stock
Just deleting them all
rm -r ~/.npm/_npx/