使用package.json 屬性說明
-
name - 包名。
-
version - 包的版本號。
-
description - 包的描述。
-
homepage - 包的官網 url 。
-
author - 包的作者姓名。
-
contributors - 包的其他貢獻者姓名。
-
dependencies - 依賴包列表。如果依賴包沒有安裝,npm 會自動將依賴包安裝在 node_module 目錄下。
-
repository - 包代碼存放的地方的類型,可以是 git 或 svn,git 可在 Github 上。
-
main - main 字段是一個模塊ID,它是一個指向你程序的主要項目。就是說,如果你包的名字叫 express,然后用戶安裝它,然后require("express")。
-
keywords - 關鍵字
卸載模塊
我們可以使用以下命令來卸載 Node.js 模塊。
$ npm uninstall express
卸載后,你可以到 /node_modules/ 目錄下查看包是否還存在,或者使用以下命令查看:
$ npm ls
更新模塊
我們可以使用以下命令更新模塊:
$ npm update express
搜索模塊
使用以下來搜索模塊:
$ npm search express
創建模塊
創建模塊,package.json 文件是必不可少的。我們可以使用 NPM 生成 package.json 文件,生成的文件包含了基本的結果。
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (node_modules) runoob # 模塊名
version: (1.0.0)
description: Node.js 測試模塊(www.runoob.com) # 描述
entry point: (index.js)
test command: make test
git repository: https://github.com/runoob/runoob.git # Github 地址
keywords:
author:
license: (ISC)
About to write to ……/node_modules/package.json: # 生成地址
{
"name": "runoob",
"version": "1.0.0",
"description": "Node.js 測試模塊(www.runoob.com)",
……
}
Is this ok? (yes) yes
以上的信息,你需要根據你自己的情況輸入。在最后輸入 "yes" 后會生成 package.json 文件。
