npm ultra-detailed entry-source management | frequently used instructions | Download | Taobao source uninstall

npm is installed together with Node.JS package management tool , with the development node, the node has now become a major ecological, maybe a lot of people do not do something node, but also used to npm.
I have nothing to write a detailed entry bar. From how to do, what it is, it represents the what, why will begin, like github tutorials, taught, white can understand tutorial

Now npm, as long as you install the nodejs, inside comes with a npm, did not go nodejs installed, I wrote a blog on the installation configuration of nodejs .

If it is white, according to my order seriously look down from above, if will use the directory can click on to find what you need.

He said nodejs is a package management tool, is that you can write someone else has already written download package, and then you come directly on the line. You can understand npm is similar to the 360 ​​software housekeeper, Ann cool stuff like this.

  • You can use the software housekeeper: search software, download software, uninstall the software
  • You can use npm: search package, the download package, delete the package

npm mirror source

Download will certainly be the source of downloads, but download the source npm abroad, that is npmjs.org, according to our domestic situation, foreign download something particularly slow. This time we have to think of a Kazakh domestic sources have not downloaded it? (• ᴗ •) و ̑̑ course there, Ali will do this in a million. Click to view Taobao npm source ( believe me look at the tutorial, do not look at this web site add written tutorial ).
Introduce Taobao Source : is a complete npmjs.orgimage, you can rest assured Taobao source instead of the official version, it is every ten minutes following the official release of updated.

First open your cmd, there gitbash with gitbash can.

You can be understood as gitbash is the function of more than cmd cmd, gitbash can use git commands also supports cmd command.

  • In a folder open cmd: you just type cmd, and press Enter in the address bar.
    Here Insert Picture Description
  • Open a folder gitbash: you can just right-gitbash here
    Here Insert Picture Description

I am here to show you the use gitbash.

View source

Since it is a source of change, that I should teach about how to view Yuanyuan:
npm config list
that is, check your npm source, here is my official sources I usednpmjs.org
Here Insert Picture Description

Taobao cnpm using command-line tool

Taobao source added:
npm install -g cnpm --registry=https://registry.npm.taobao.org
here the meaning of this sentence is to use

  • npm install npm install
  • -gGlobal (Why do not control the overall situation, I'll explain behind)
  • cnpmHe said on behalf of a just, you can write another name
  • --registry=https://registry.npm.taobao.orgaddress

Once you have entered two under the carriage did not react, do not worry, after all, the installation takes time. The last show this to prove that you Taobao success source added.
Here Insert Picture Description

After you have added the source Taobao look at whether we have to change the source. Enter the View Source command after? ? ? (╯ `□ ') ╯(┻━┻ liar, say good can change it! How or official sources. Look down.
Here Insert Picture Description
This is because you just command it, I said, is to add the source, not a replacement source , that is, even if you add Taobao source, your official source is also still there, is still possible to use the above shall say cnpm is that you can change their own names, that is, you want to see Taobao source, need to use the name of Taobao sources to view wailing. I use is cnpm, so I want to see Taobao source will need to enter
cnpm config list
Kan Ma, Taobao is successfully added the source. Do not stop! continue to see the replacement source !!!
Here Insert Picture Description

Taobao cnpm delete uninstall tool (skip this and look down)

Just saw it was thinking: Why add Taobao source, there is a unload ah, why there is a replacement source added ah, why there are replaced by nrm ah. After reading the results nrm: (=゚ω゚) Techno nrm really fragrant after, know nrm, cnpm command-line tool is put away. You can directly uninstall the cnpm.
npm uninstall cnpm -g
Uninstall, then enter
Here Insert Picture Description

Replacement source

But I just want to say you want to change the source! I just do not want to use the official source! Well then you change.
npm config set registry https://registry.npm.taobao.org/( configWrite do not write anything, do not write can change.)
What this means is to give npm the source said on behalf of the exchange Taobao. After you change the look, that's been changed, you npm Taobao is the source! ! !
Here Insert Picture Description

nrm source management (can quickly change the source)

Then you want to say, if I want to see how to do all of my sources, I can not remember every name and then one by one config list it. (●'ω `●) wit as I tell you how to engage a source manager:
npm install nrm -g --save

  • npm install nrmnpm install nrm
  • -g --saveThis behind me say, first do not tangle what that means.

If you just added a cnpm, you can try using your cnpm installation.
cnpm install nrm -g --save
Installation requires process Well, if you enter the command did not respond to wait a while. 눈 _ 눈 do not worry. Below this is the download finished.
Here Insert Picture Description
After the download is complete you can use.

See all sources

nrm ls
See all your sources. After reading a bunch of question marks and you beat my face, What the hell, I'm not in the previous step is to add a source called cnpm Taobao it, not now how cnpm address Taobao, Taobao source called taobao?
Here Insert Picture Description
because! nrm is designed to manage and fast switching private registry configuration. Is the big top of the steps can be omitted.

Rapid switching Source

nrm use 名字You can substitute the phrase npm config set registry 地址
first method, although the trouble, but still have to teach Well, if someone does not want to install nrm.
Continue to look at, for example, I want to change the source http://r.cnpmjs.org/, he said on behalf of a cnpm, I can direct nrm use cnpm, but also finished check is really changed.
Here Insert Picture Description
If you entered the company, the company has its own mirror image,

Add Source

nrm add 名字 地址
I just wrote a:
Here Insert Picture Description

Delete source

nrm del 名字
Here Insert Picture Description

Speed ​​test response

nrm test npm
The rollover on my computer, and display response speed is said to be, but I never displayed on the computer. Never did the following. Only close and reopen.

Common commands npm

Below is npm common commands, will explain -g --save on top of what it is, I do not understand can look at.

View version

npm -vView npm version
npm versionView all versions of the module
Here Insert Picture DescriptionHere Insert Picture Description

Initialize the project / package

If you go to a file folder to download a package, preferably init, let npm know this is you want to download destination folder, or even if you get into that folder, it may be the wrong location wailing. But do not worry about the wrong position, you just folders on a network, on the upper level, has been to find the root directory, always finds.
npm initInitialize the project, followed by the init he will prompt you to let you enter some information. If you do not want to enter this information, you can directly use npm init -f
I npm initshow you:

  • package name is your package name, the default is the name of the folder you enter, if it is determined that name you can directly enter
  • version version of the package, default 1.0.0, you just confirmed it, if you want to change on a whim
  • description add descriptive information, do not want to add directly enter, try to add on, or else npm will always prompt warning
  • Inside the entry point is a reference to another file, but there is always a file is the last file, the other file only lead, then he is the entrance file, the default index.js, directly enter just fine. If you are not entry file index, then modify (this is not even now directly Enter on the line.)
  • I forgot to test command is valid, the right of the Enter
  • git repository git address, no words are not filled, it is best just to write, or else npm will always prompt warning
  • keyword keywords, just like paper, like, people can set keywords to your keyword search package
  • author author, did not want to write the name Enter
  • Enter license

So you built a package. Now you look at your folder on the more out of a package.json, inside information you just entered, you can modify oh.
Here Insert Picture Description
Here Insert Picture Description

Search package

Search package you need, just the process of construction projects taught to create json, there will be a keywords, this change is to follow the search. I demonstrate it Search math
npm search 关键字ornpm s 关键字

If the following error, put your back to the source's official website source on it. It is said to Taobao source appears small problems, the search will get an error, you can use the official source search, sources with Taobao download (? Is too easy to lose nrm Well)

npm WARN search fast search endpoint errored. Using old search.
npm WARN Failed to read search cache. Rebuilding
npm WARN Building the local index for the first time, please be patient
npm WARN Search data request failed, search might be stale
npm ERR! No search sources available
npm search math

Here Insert Picture Description

Installation package

  1. npm install 包名Or npm i 包名
    after installation you look at your folder on one more node_modules folder, which will have the math.
    There are two caveats below do not bother, because when I did not just init git add descriptions and addresses, will not be prompted to add.
    Here Insert Picture Description

  2. npm install 包名 -gOr npm i 包名 -g
    global installation (usually some tools, such as cnpm, such as nrm, this project is more than you use.)
    npm root -gYou can view the global installation directory. I am here to show this address, I entered the address, you can see just globally installed nrm folder.
    Here Insert Picture Description
    Here Insert Picture Description

  3. npm install 包名 --saveAlternatively npm i 包名 --save( --saveto be written -S)
    to install the package and add the specified dependencies. Attention! ! ! This is more important! ! ! But also below the 5 important, ah, look at to understand 3 5 ah! ! !
    There are two caveats below do not bother, because when I did not just init git add descriptions and addresses, will not be prompted to add.
    Here Insert Picture Description

    Why is --saveimportant, because if not, your dependencies inside may not write your download package (do not add dependencies) . Here Insert Picture Description
    Do not write your download package (do not add dependencies) , which may have little effect on you. But the analysis of what wailing:

    • You need to download someone else's bag
    • You download this package, you may also use other people's packages
    • Then how do you know with what other packages? We have to look dependencies.
      • Because then finished out the package, upload time is not without node_modules folder.
        • Why not take node_modules folder
          • Because you are using a package written by someone else, you upload the associated modules folder,
            it will cause my bag still with someone else's bag, it would mean that an infinite set of her?
        • Therefore, the packages are uploaded without node_modules this folder
      • Without node_modules, you want to use this package
      • You have to own the whole download your download package have used what package
      • So you need to look at the dependencies.
    • So you might as well use -save, add to their package dependencies.
    • 눈 _ 눈 you might say, "okay, I am little spicy chicken, no one with my bag," if one day you will become chiefs of it, they still add --saveit.
  4. npm install
    Add node_modules, and install any dependencies. What I just said, since downloading someone else's bag, that people might use the other packages, how to do that, one by one download it? In fact, the file you just go to add a dependency of the package folder, npm installyou can install all dependencies.
    For example, my demo, inside add a dependent, it is math. Now, I node_modules delete and pretend I was under the package, which rely only wrote, but did not node_modules folder. $ npm installAfter you'll find inside reliance installed Qi.
    Here Insert Picture Description

  5. npm install 包名 --save-devOr npm i 包名 --save --dev(not strict wording --save--devcan also write -Dlowercase will do. --devWriting -devwill do)
    ** 5. Super important! More than 3 used in the work. ** The reason you can see the end.

note! ! ! I finally add a bit --save-devmore than --savethe difference, you can go and see.

Delete Package

  1. npm remove 包名Or npm r 包名
    delete a package, there are two caveats below do not bother, because when I did not just init git add descriptions and addresses, will not be prompted to add.
    Here Insert Picture Description
  2. npm uninstall 包名ornpm uni 包名
  3. npm uninstall 包名 -g(If you use the installation npm install 包名 -g)
  4. npm uninstall 包名 --save(If you install using a npm install 包名 --save)
    npm uninstall 包名 --save-dev(if you use the installation npm install 包名 --save-dev)

The difference npm install -S -D

  1. npm install 名字 -S=npm install 名字 --save
    (1) will need to use the package to the node_modulesfolder
    (2) will package.jsonof adding a dependency property at run after (3) npm install command, to automatically install dependencies node_modules directory run after (4) or specified variable value when, it will be automatically installed to rely directory dependencies

    npm install --productionNODE_ENVproductionnode_modules
  2. npm install 名字 -D=npm install 名字 --save-dev
    (1) will need to use the package to the node_modulesfolder (upper side and the same)
    (2) will package.jsonof adding a dependency property under (3) when running npm install after the command, to automatically install dependencies node_modules directory (and upper Like) after running (4) or specified variable value when not automatically installed to rely directory devDependencies

    npm install --productionNODE_ENVproductionnode_modules

dependencies and configuration information package.json devDependencies are in. More than a different name. So why the former will be automatically installed to rely on node_modules, the latter will not automatically install dependent on the node_modulesfolder?
dependencies and devDependencies difference:

  • dependencies
    is dependent on the production environment. Production stage to use, is to release versions for others to use.
  • devDependencies
    is dependent on the development environment. Production phase and the development phase is to be used, is that you usually write it, and when to publish.

For example, for example, you write a program, use the webpack inside, but you will finish it later, you can let others use, but the course has no need webpack, and therefore can not be installed.
To distinguish your development process relies on devDependencies put in, it proved to be something you need to develop, and when people use is not automatically installed node_modules in, because the things you used in the development of other longer required ; but when your project is released, it will have to rely on those dependencies into, because these essential.
As another chestnut, for example, I want to be a gift to my good friend, I decided to sew a bear. Then I bought diy material package started. This time the whole bag of tools on the material devDependencies years. Bear sew after I gave my good friends. I gave him a bear on the line, the Bears have sew, sewing what is not necessary to him. So just bear in Dependencies.


I'm Lolita Ann. Thanks to their own way of learning, but it should not be wrong. If there is a problem somewhere, then please correct me (• ㅂ •) / ♥

Published 131 original articles · won praise 451 · views 540 000 +

Guess you like

Origin blog.csdn.net/qq_36667170/article/details/104942300