歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> node.js 第三方模塊如何安裝(使用npm)及介紹

node.js 第三方模塊如何安裝(使用npm)及介紹

日期:2017/2/28 15:57:24   编辑:Linux教程

寫java代碼,遇到問題首先去找相關的第三方APi,已經成為習慣了,java的第三方api真的是太多了。不過也不用羨慕java,node.js也不少,看看官網的介紹:

官方文檔的最下面 Appendix 1: Recommended Third-party Modules ,這裡是關於第三方模塊的介紹,第一段:There are many third party modules for Node. At the time of writing, August 2010, the master repository of modules is the wiki page. 打開這個鏈接你會發現相當多的第三方模塊,上百個是少不了的。

要安裝使用這些模塊需要使用npm(Node Package Manager)工具,該工具node.js已經集成,這個工具給我感覺像maven。打開命令行,執行npm -h(通常命令行應用程序都可以這樣查看幫助,或者是/?,--help),結果如下:


發現有install和uninstall命令,這個就應該是安裝和卸載的命令。根據說明以下方式可以查到具體幫助

npm install -h 結果如下:


這個幫助比較簡單,具體的可以使用

npm help install 結果如下:




網頁有該命令非常詳細的介紹。uninstall也同樣使用上述方法。


通常在網上看到安裝是使用的這種方式 npm install connect,即 npm install <name>。那為什麼只是給了name它就能安裝,安裝地址在哪啊?

install文檔中提到了 a <name>@<version> that is published on the registry with (c)

那就看以下registry 的說明,文檔下方SEE ALSO中有鏈接

registry文檔中有下面一段話 To resolve packages by name and version, npm talks to a registry website

that implements the CommonJS Package Registry specification for reading package info.

可以看出名稱是由它來解析的,那地址在哪了,下面還有一句

The registry URL is supplied by the registry config parameter. See config(1) for more on managing npm's configuration.

Copyright © Linux教程網 All Rights Reserved