標籤:des blog http io ar os java sp strong
package.json 中包含各種所需模組以及項目的配置資訊(名稱、版本、許可證等)meta 資訊。
包含可配置項
- name 名稱
- 應用描述 description
- 版本號碼 version
- 應用的配置項 config
- 作者 author
- 資源倉庫地址 respository
- 授權方式 licenses
- 目錄 directories
- 應用入口檔案 main
- 命令列檔案 bin
- 項目應用運行相依模組 dependencies
- 項目應用開發環境依賴 devDependencies
- 運行引擎 engines
- 指令碼 script
簡單模式
==========================
{ name: "myApp", version :"0.0.1" }
完整模式
===========================
{ "name": "myApp", "version": "0.0.0", "author" : "simple", "description" : "Nodejs Package json介紹", "keywords" : "javascript, nodejs", "respository" : { "type" :"git", "url" :"http://path/to/url" }, "bugs" : { "url" : "http://path/to/bug", "email" : "[email protected]" }, "contributors" : [ {"name" : "zhangsan", "email" : "[email protected]" ] "license" : "MIT", "engines" : { "node" : "0.10.x"}, "script" : { "start" : "node index.js" }, "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "express": "~4.9.0", "body-parser": "~1.8.1", "cookie-parser": "~1.3.3", "morgan": "~1.3.0", "serve-favicon": "~2.1.3", "debug": "~2.0.0", "jade": "~1.6.0" }, "devDependencies": { "bower" : "~1.2.8", "grunt" : "~0.4.1", "grunt-contrib-concat" : "~0.3.0", "grunt-contrib-jshint" : "~0.7.2", "grunt-contrib-uglify" : "~0.2.7", "grunt-contrib-clean" : "~0.5.0", "browserify" : "2.36.1", "grunt-browserify" : "~1.3.0" }}
1.scripts
運行指定指令碼命令。
2.
npm install express --save
npm install express --save-dev
上面代碼錶示單獨安裝express模組,
--save參數表示將該模組寫入dependencies屬性,
--save-dev表示將該模組寫入devDependencies屬性。
3.關於指定版本號碼
(1)波浪號~(tilde)+指定版本:比如~1.2.2,表示安裝1.2.x的最新版本(不低於1.2.2),但是不安裝1.3.x,也就是說安裝時不改變大版本號碼和次要版本號碼。
NodeJS中 package.json 解析