Skip to content

Commit 27c8a8b

Browse files
author
caesar_chi
committed
add npm part
1 parent 482cdc4 commit 27c8a8b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
* JavaScript 介紹
1414
* [JavaScript 介紹](javascript_tour/introjs.md)
1515
* [JavaScript 變數型別,宣告](javascript_tour/variablejs.md)
16+
* npm 介紹
17+
* [npm 基本使用](npm_tour/intro_npm.md)
18+
* [npm 進階介紹](npm_tour/parameter_npm.md)
1619
* [實戰範例](install/installNode.md)
1720
* [如何使用範例程式?](example/howto.md)

npm_tour/intro_npm.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#npm 介紹
2+
3+
npm 在 Node.js v0.6.x 版本之後,就變成內建的系統之一,npm 全名為 Node.js Package Management,主要用於套件管理,這也表示當 Node.js 安裝完成之後就可以直接使用 npm 這個指令。至於 npm 有什麼強大之處,接下來慢慢介紹。
4+
5+
##npm 基本使用方法
6+
7+
Node.js 其中好用的一個部份就是因為有 npm,擁有完整管理的架構,讓套件可以被妥善管理,每個專案間的 dependency 也可以妥當的被使用,目前在 npm 上也已經有 8000 多個模組,提供開發者使用。
8+
基於開發者不要重複自己造輪子,從 npm 上面找到適合自己的模組,就是開發者應該做的工作。
9+
10+
* [npm 資料網站](https://npmjs.org/)
11+
12+
可以從上面的網站找到許多套件,使用方法也非常簡單,內容詳細的項目,可以參考 npm 的說明,在終端機輸入 npm ,會得到如下的訊息,
13+
14+
where is one of:
15+
add-user, adduser, apihelp, author, bin, bugs, c, cache,
16+
completion, config, ddp, dedupe, deprecate, docs, edit,
17+
explore, faq, find, find-dupes, get, help, help-search,
18+
home, i, info, init, install, la, link, list, ll, ln, login,
19+
ls, outdated, owner, pack, prefix, prune, publish, r, rb,
20+
rebuild, remove, restart, rm, root, run-script, s, se,
21+
search, set, show, shrinkwrap, star, start, stop, submodule,
22+
tag, test, tst, un, uninstall, unlink, unpublish, unstar,
23+
up, update, version, view, whoami
24+
25+
npm -h quick help on
26+
npm -l display full usage info
27+
npm faq commonly asked questions
28+
npm help search for help on
29+
npm help npm involved overview
30+
31+
Specify configs in the ini-formatted file:
32+
/Users/caesar/.npmrc
33+
or on the command line via: npm --key value
34+
Config info can be viewed via: npm help config
35+
36+
如果想要知道每個項目要怎麼使用,可以輸入如下的範例
37+
38+
npm [action] -h
39+
40+
例如
41+
42+
npm tag -h
43+
44+
輸入上面的指令,加上 -h 的參數之後,就可以得到解釋。
45+
46+
npm install
47+
48+
用於安裝 node module,描述如下,我們以 Express 為例,
49+
50+
npm install [email protected]
51+
52+
如此就可以安裝 express 的套件。
53+
54+
##npm 全域安裝
55+
56+
npm 全域安裝指的是當此套件擁有指令模式的時候,可以使用 npm install -g ,讓模組的指令可以直接在系統上執行。
57+
58+
npm install -g [email protected]
59+
60+
安裝完成之後就可以使用在系統上使用 express 這個指令。
61+
62+
express test
63+
64+
就可以使用 Express 指令產生新的專案 。
65+
另外如果希望安裝 express 舊有版本的時候,可以直接使用
66+
67+
npm install [email protected]
68+
69+
輸入上面的指令 express 2.8.5 就會被安裝完成。如果是為於某個專案底下,同時 node project 中也有設定 package.json 的話,就可以直接使用,
70+
71+
npm install .
72+
73+
如此就會去讀取 package.json 當中的 dependencies ,找到需要安裝的模組,安裝到此目錄的 node_modules 目錄當中。
74+
75+
npm list
76+
77+
列出目前安裝的 node module 有哪些,
78+
79+
// 列出目前 node moulde
80+
npm list
81+
82+
輸入如上的指令,如果沒有位於任何 node project 底下的時候,是不會顯示任何模組,這是因為 npm 會去讀取 package.json,取得相依的 package 之後,再到此目錄底下的 node_modules 底下找相關模組是否已經被安裝。
83+
84+
// 列出全域安裝的 node module
85+
npm list -g
86+
87+
如果輸入上面的指令,就會得到目前使用 npm 已經安裝多少全域的模組,將會全部被列出來。
88+
89+
npm 另外一個強大的部份在於 [npmjs.org 網站](https://npmjs.org/) 上面的註冊、管理、上傳設定,讓自己開發的 node modules 也可以透過 npm 進行安裝,但是在這個章節,不會教導這麼多,這個部份,歡迎有興趣的人自己去找尋答案,或者到 Node.js Taiwan 社群討論。
90+
安裝完 node.js 也了解 npm 之後,接著可以開始進行我們的第一個 node 程式,進行自己的 node.js 開發第一步。

npm_tour/parameter_npm.md

Whitespace-only changes.

0 commit comments

Comments
 (0)