What npm that?
It is the world's largest software registry, every week there are about 3 billion downloads, including more than 600,000 packages (Package Penalty for) . The registry is a huge database, save for each package (package) information on open source software developers from every continent using npm share and learn from each other. The structure of the package allows you to easily keep track of dependencies and versions.
Briefly, NPM is filled with a block of code, frameworks, libraries, and so on ... package
NPM is accompanied NodeJS package management tools installed together, can solve many problems on NodeJS deployed code, common usage scenarios are the following:
- NPM allows users to download from the server written by someone else third-party packages to local use.
- It allows users to download and install the command-line program written by someone else to use local NPM from the server.
- It allows users to write their own bag or command line program NPM uploaded to the server for others to use.
What can solve the problem
When a project depends more and more code:
1. go to the official website to download jQuery jQuery
2. go BootStrap official website to download BootStrap
3. Underscore the official website to download Underscore
....
By node built npm, it can be the perfect solution.
how to use
Provided that the computer has been configured node environment, and node version 6. +
1. Hold down the shift + right mouse button to download folder, open a command window
2. Initialization: Enter npm init
There will be a survey form out, then keep pressing Enter until folder file appears package.json
3. Install: Enter the name of npm install package
Download the latest version default
Download the specified version of the package, enter npm install the package name @ version number
After downloading the file package.json:
"dependencies": {
"jquery": "^3.4.1"
}
dependencies: dependence
package.json objects there are dependencies download package name and version number
Global Path: Input: cnpm install the package name -g
C:\Users\Administrator\AppData\Roaming\npm\node_modules
4. Remove the packages, enter: npm Uninstall remove the package name
As shown below:
Other operations:
npm -v view the version, the test is successfully installed
npm list to view the list of downloaded packages
npm generally used for background downloading (node) of the package, the package can be downloaded foreground, but not recommended to download the package front desk, front desk has its own package management tool bower, bower belonging to the backstage management tool, the relationship between them is: by npm management bower, bower by the front desk management package.
Extension: cnpm (Taobao mirror)
Since npm install the plug-in is downloaded from the server abroad, by the impact of a large network, it may appear abnormal, Taobao team made npm is a domestic version of the synchronization foreign npm, updated every 10 minutes, even faster download speeds using cnpm
how to use:
After initialization npm, can always enter: npm install -g cnpm -registry = https: //registry.npm.taobao.org
Wait for the download is complete
Initialization: Enter cnpm init
Other npm the same operation, the npm replaced cnpm
And npm different :
Package.json update file, enter: cnpm install the package name --save
Note: The download process appears in red, indicating an error during the download, this time only need to re-download it, if not enough to direct the seamless handover Download npm, without having to re-initialize.