What is NPM? What is NPX? What is NVM? What is NRM? Can you tell them apart
npm
NPM, Node Package Manager, is the Package management tool for the JavaScript world and the default Package management tool for the Node.js platform. NPM allows you to install, share, distribute code, and manage project dependencies.
Common commands
NPM install Installs the module NPM uninstall Uninstalls the module NPM update Updates the module NPM outdated Check whether the module is outdated NPM ls Check the installed module NPM init NPM help View the detailed help of a command NPM root View the installation path of the package NPM config Manage the configuration path of the NPM NPM Cache Cache of the management module NPM start Start the module NPM stop Stop the module NPM restart Restart the module NPM test Test the module NPM version Check the module version NPM view Check the module registration information NPM adduser Log in to NPM publish publish module NPM Access sets the syntax for the access level NPM package.json on published packagesCopy the code
NPM uploads its own package
NPM install AAA // Check whether the NPM existsCopy the code
- If you do not create a AAA folder
cd AAA>
npm init -y
Copy the code
- Enter the package.json file
"Name", "AAA", / / mandatory fields name "version" : "0.0.1" / / "main" : mandatory version information '. / dist/index. Js' in the name of the file address / / exposureCopy the code
- Login NPM
NPM login // Enter a user name, password, and email addressCopy the code
No account went to (NPM)[www.npmjs.com/] to register an account
- When updating the NPM package, remember to change the version version information in the package.json folder
- perform
npm publish
Copy the code
- Use NPM to undo the distribution package
NPM unpublish package nameCopy the code
- NPM install AAA –save-dev will load your package in the project you need
nvm
- Sometimes during development, there are requirements for the node version, and sometimes you need to switch to the specified node version to reproduce problems, etc. When faced with this requirement, we need to be able to switch node versions flexibly
- NVM was created to solve this problem by making it easy to switch between multiple Node versions on the same device
Common commands
NPM install -g NRM install ## NVM uninstall ## uninstall ## NVM uninstall ## NVM ls ## List all installed versions NVM ls-remote ## list all remote server versions (official node version list) NVM current NVM unalias ## Delete the defined alias NVM scanted-packages ## Reinstall the specified NPM package globally in the current Node version environmentCopy the code
- NVM does not support Windows, but there is an alternative, namely NVM-Windows,
n
- N is a node module that can be used to manage and switch node versions. It was written by TJ Holowaychuk (well known as the author of the Express framework) and is very simple to use.
Common commands
NPM install -g n n // Check the installed version n latest // Install the latest version and use n latest -d // Download the latest version but do not use it, The -d parameter indicates that only n stable is downloaded // Install the latest stable version and use n <version> // Install a version and use it, for example, $n 6.2.2n rm <version... > // Delete some versions n ls // View the available version n --latest // View the latest version n --stable // View the latest stable version n -h // View the help information. For more commands, see hereCopy the code
- This means that before we can use n to manage the Node version, we first need a Node environment. We can either install a Node using Homebrew (MAC), or download a PKG from the official website to install a Node — n itself cannot be installed.
NRM freely switches over NPM sources
- NRM (NPM Registry Manager) is an NPM resource manager that allows you to quickly switch NPM sources
Common commands
NPM install -g NRM NRM install NRM ls Lists available sources NRM use Taobao Select the source NRM test NPM test speed NRM add Taobao http://192.168.10.127:8081/repository/npm-public/ added source NRM del taobao to delete the corresponding sourceCopy the code
npx
- A command (NPX) introduced in NPM v5.2.0 that will execute the binary files in the dependency package for you. The purpose of introducing this command is to improve the developer experience with the command line tools provided with the package
- Install a parcel globally, but sometimes different projects use different versions that don’t allow global packages, so consider using NPM scripts and adding a script to package.json to add the executable directory for node_modules to the PATH. Specify an executable command path
- When we execute NPX parcel index.html, it automatically searches for./node_modules/.bin.
old:
npm install -g create-react-app
create-react-app my-app
new:
npx create-react-app my-app
Copy the code