This is the 11th day of my participation in the August More Text Challenge. For details, see:August is more challenging
preface
What is NPM?
NPM is a package management tool for JavaScript
NPM opens the door for you and your team to connect the entire world of JavaScript geniuses. It is the largest software registry in the world, with about 3 billion downloads per week and more than 600,000 packages (that is, code modules). Open source software developers from all continents use NPM to share and learn from each other. The structure of the package enables you to easily track dependencies and versions.
NPM Common commands
View the NPM version
npm -v
Copy the code
Upgrade the global NPM
sudo npm install npm -g
Copy the code
If the system is Windows, run the following command:
npm install npm -g
Copy the code
NPM help
npm help
Copy the code
NPM Clears the cache
npm cache clear
Copy the code
The module
Install the module
NPM insatll express NPM install // Install all modules in current package.jsonCopy the code
Uninstall the module
npm uninstall express
Copy the code
View the current NPM /node_modules/ package list
npm ls
Copy the code
Search module
npm search express
Copy the code
The update module
npm update express
Copy the code
NPM address configuration
-
The original address of NPM
npm config set registry http://registry.npmjs.org
Copy the code
-
Setting the domestic Image
A. Run the config command
NPM config set registry https://registry.npm.taobao.org NPM info the underscore (if there could be strings configured properly this command response)Copy the code
B. Specify on the command line
npm --registry https://registry.npm.taobao.org info underscore
Copy the code
C. Edit ~/.npmrc to add the following content
registry = https://registry.npm.taobao.org
Copy the code
-
Use NRM to manage the Registry address
A. download the NRM
npm install -g nrm
Copy the code
B. Add the Registry address
nrm add npm http://registry.npmjs.org
nrm add taobao https://registry.npm.taobao.org
Copy the code
C. Switch the NPM Registry address
nrm use taobao
nrm use npm
Copy the code
other
Viewing basic Configurations
NPM config list NPM config list -l // View all configurationsCopy the code
What is the difference between a NPM local installation and a global installation?
NPM install grunt // Download the module to the directory where the current command line is located. NPM install -g grunt// The module will be downloaded and installed in the [global] directory;Copy the code
NPM How do I obtain the default directory for global installation?
NPM config get prefix NPM How do I set the default directory for global installation? NPM config set prefix "directory"Copy the code
NPM release undo
Release NPM package
npm publish
Copy the code
Revocation of NPM package
npm unpublish
Copy the code
The version number
Version numbers are accessed when you download and distribute code using NPM. NPM uses semantic version numbers to manage code, which are briefly introduced here.
The semantic version number consists of X.Y.Z, which represents the major version number, minor version number, and patch version number. When code changes, the version number is updated as follows.
- If you’re just fixing a bug, you need to update the Z bit.
- If the new function is backward compatible, you need to update the Y bit.
- If there is a big change, downward incompatibility, need to update the X bit.
With this guarantee in place, when declaring third-party package dependencies, you can rely not only on a fixed version number but also on a range of version numbers. For example, “argv”: “0.0.x” means relying on the latest version of the 0.0.x series argV.
You can view the official document to specify all version ranges supported by NPM.