NPM

NPM stands for Node Package Manager. It is the Package Manager for Node.js, whose goal is to automate dependency and Package management.

This means that you can specify all dependencies (packages) for your project in a package.json file, and when you need to install dependencies for it, you simply run NPM install.

NPM itself cannot execute any packages. If you want to execute a package from a local project, you need to write it to package.json, parse the package.json file through NPM, parse it to the bin path of the package, and execute it in bash.

NPX

NPX is a tool, NPM V5.2.0 introduced a command (NPX), an NPM package actuator, to improve the experience when using software packages from the NPM registry, NPM makes it very easy to install and manage dependencies hosted on the registry, NPX makes it very easy to use CLI tools and other hosted in the registry.

So now most developers have direct access to the functionality of NPX.

NPX is still a simple CLI tool that makes it easier to execute some NPM packages without having to install them on a developer’s computer via NPM.

Main features: 1, temporary installation can execute dependency package, do not need to install globally, do not worry about long-term pollution. 2. You can run the commands in the dependency package to automatically run the installation. Automatically load dependencies on node_modules without specifying $PATH. 4. You can specify the node version and command version, which solves the problem that different projects use different versions of commands.

conclusion

NPX extends the NPM file execution function to provide a new way to use the Node.js CLI tool, which is more flexible than previous implementations and less polluting to local environment variables (you can check it out in your node installation directory, How many soft links in the bin directory are contaminating your environment variables? Specifying the functionality of the package version gives us the flexibility to test new features without upgrading or downgrading them, which is a great convenience.