OSDN Git Service

Regular updates
[twpd/master.git] / package.json.md
1 ---
2 title: package.json
3 category: Node.js
4 layout: 2017/sheet
5 prism_languages: [json]
6 updated: 2017-08-30
7 weight: -3
8 ---
9
10 ### Basic
11
12 ```json
13 {
14   "name": "expo",
15   "description": "My package",
16   "version": "0.1.0",
17   "license": "MIT",
18   "keywords": ["http", "server"],
19   "author": "Rico Sta. Cruz <rstacruz@users.noreply.github.com>",
20   "engines": {
21     "node": ">=0.8.0"
22   },
23   "main": "index",
24   "bin": {
25     "command": "./bin/command"
26   },
27   "repository": {
28     "type": "git",
29     "url": "https://github.com/rstacruz/___.git"
30   },
31 }
32 ```
33 {: data-line="2,3,4,5"}
34
35 Highlighted lines are required.
36
37 ### Dependencies
38
39 ```json
40 "dependencies": {
41   "colors":   "*",
42   "flatiron": "0.1.x",
43   "flatiron": "~0.1.0",
44   "plates":   "https://github.com/user/project/tarball/branch",
45   "stuff":    "git://github.com/user/project.git#commit-ish"
46 },
47 ```
48
49 ```json
50 "devDependencies": { ··· },
51 "peerDependencies": { ··· },
52 "optionalDependencies": { ··· },
53 ```
54
55 See [Semver cheatsheet](./semver) for explanation of version ranges.
56
57 ### Scripts
58
59 ```json
60 "scripts": {
61   "start": "node ./bin/xxx",       /* npm start */
62   "test": "vows --spec --isolate", /* npm test */
63   "postinstall": "...",
64   "prepublish": "grunt build",     /* after 'npm install' and before 'npm 
65                                       publish' */
66 }
67 ```
68
69 ### Misc
70
71 ```json
72 "private": true,
73 "preferGlobal": true
74 ```
75
76 ### Config
77
78 ```json
79 {
80   "config": {
81     "foobar": "hello"
82   },
83   "scripts": {
84     "run": "echo $npm_package_config_foobar"
85   }
86 }
87 ```
88
89 Keys in `config` are exposed as env vars to scripts.
90
91 ## References
92 {: .-one-column}
93
94  * <http://package.json.nodejitsu.com/>
95  * `npm help package.json`
96 {: .-also-see}