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.
Article Directory
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.org
image, 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.
- Open a folder gitbash: you can just right-gitbash here
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
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-g
Global (Why do not control the overall situation, I'll explain behind)cnpm
He said on behalf of a just, you can write another name--registry=https://registry.npm.taobao.org
address
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.
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.
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 !!!
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
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/
( config
Write 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! ! !
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 nrm
npm install nrm-g --save
This 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.
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?
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.
If you entered the company, the company has its own mirror image,
Add Source
nrm add 名字 地址
I just wrote a:
Delete source
nrm del 名字
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 -v
View npm version
npm version
View all versions of the module
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 init
Initialize 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 init
show 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.
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
Installation package
-
npm install 包名
Ornpm 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.
-
npm install 包名 -g
Ornpm i 包名 -g
global installation (usually some tools, such as cnpm, such as nrm, this project is more than you use.)
npm root -g
You 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.
-
npm install 包名 --save
Alternativelynpm i 包名 --save
(--save
to 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.
Why is
--save
important, because if not, your dependencies inside may not write your download package (do not add dependencies) .
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?
- Because you are using a package written by someone else, you upload the associated modules folder,
- Therefore, the packages are uploaded without node_modules this folder
- Why not take node_modules 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.
- Because then finished out the package, upload time is not without node_modules folder.
- 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
--save
it.
-
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 install
you 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 install
After you'll find inside reliance installed Qi.
-
npm install 包名 --save-dev
Ornpm i 包名 --save --dev
(not strict wording--save--dev
can also write-D
lowercase will do.--dev
Writing-dev
will 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-dev
more than --save
the difference, you can go and see.
Delete Package
npm remove 包名
Ornpm 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.
npm uninstall 包名
ornpm uni 包名
npm uninstall 包名 -g
(If you use the installationnpm install 包名 -g
)npm uninstall 包名 --save
(If you install using anpm install 包名 --save
)
npm uninstall 包名 --save-dev
(if you use the installationnpm install 包名 --save-dev
)
The difference npm install -S -D
npm install 名字 -S
=npm install 名字 --save
(1) will need to use the package to thenode_modules
folder
(2) willpackage.json
of 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 directorydependencies
npm install --production
NODE_ENV
production
node_modules
npm install 名字 -D
=npm install 名字 --save-dev
(1)will need to use the package to the(upper side and the same)node_modules
folder
(2) willpackage.json
of 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 directorydevDependencies
npm install --production
NODE_ENV
production
node_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_modules
folder?
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 (• ㅂ •) / ♥