(window.webpackJsonp=window.webpackJsonp||[]).push([[2240],{2648:function(t,s,a){"use strict";a.r(s);var e=a(31),n=Object(e.a)({},(function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"package-json"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#package-json"}},[t._v("#")]),t._v(" package.json")]),t._v(" "),a("h2",{attrs:{id:"scripts"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#scripts"}},[t._v("#")]),t._v(" Scripts")]),t._v(" "),a("p",[t._v("You can define scripts that can be executed or are triggered before or after another script.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pretest"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/pretest.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"test"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/test.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"posttest"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/posttest.js"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("p",[t._v("In this case, you can execute the script by running either of these commands:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("$ npm run"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("script test\n$ npm run test\n$ npm test\n$ npm t\n\n")])])]),a("h3",{attrs:{id:"pre-defined-scripts"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#pre-defined-scripts"}},[t._v("#")]),t._v(" Pre-defined scripts")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("Script Name")]),t._v(" "),a("th",[t._v("Description")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("prepublish")]),t._v(" "),a("td",[t._v("Run before the package is published.")])]),t._v(" "),a("tr",[a("td",[t._v("publish, postpublish")]),t._v(" "),a("td",[t._v("Run after the package is published.")])]),t._v(" "),a("tr",[a("td",[t._v("preinstall")]),t._v(" "),a("td",[t._v("Run before the package is installed.")])]),t._v(" "),a("tr",[a("td",[t._v("install, postinstall")]),t._v(" "),a("td",[t._v("Run after the package is installed.")])]),t._v(" "),a("tr",[a("td",[t._v("preuninstall, uninstall")]),t._v(" "),a("td",[t._v("Run before the package is uninstalled.")])]),t._v(" "),a("tr",[a("td",[t._v("postuninstall")]),t._v(" "),a("td",[t._v("Run after the package is uninstalled.")])]),t._v(" "),a("tr",[a("td",[t._v("preversion, version")]),t._v(" "),a("td",[t._v("Run before bump the package version.")])]),t._v(" "),a("tr",[a("td",[t._v("postversion")]),t._v(" "),a("td",[t._v("Run after bump the package version.")])]),t._v(" "),a("tr",[a("td",[t._v("pretest, test, posttest")]),t._v(" "),a("td",[t._v("Run by the "),a("code",[t._v("npm test")]),t._v(" command")])]),t._v(" "),a("tr",[a("td",[t._v("prestop, stop, poststop")]),t._v(" "),a("td",[t._v("Run by the "),a("code",[t._v("npm stop")]),t._v(" command")])]),t._v(" "),a("tr",[a("td",[t._v("prestart, start, poststart")]),t._v(" "),a("td",[t._v("Run by the "),a("code",[t._v("npm start")]),t._v(" command")])]),t._v(" "),a("tr",[a("td",[t._v("prerestart, restart, postrestart")]),t._v(" "),a("td",[t._v("Run by the "),a("code",[t._v("npm restart")]),t._v(" command")])])])]),t._v(" "),a("h3",{attrs:{id:"user-defined-scripts"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-defined-scripts"}},[t._v("#")]),t._v(" User-defined scripts")]),t._v(" "),a("p",[t._v("You can also define your own scripts the same way you do with the pre-defined scripts:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"preci"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/preci.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ci"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/ci.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"postci"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts/postci.js"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("p",[t._v("In this case, you can execute the script by running either of these commands:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("$ npm run"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("script ci\n$ npm run ci\n\n")])])]),a("p",[t._v("User-defined scripts also supports "),a("strong",[t._v("pre")]),t._v(" and "),a("strong",[t._v("post")]),t._v(" scripts, as shown in the example above.")]),t._v(" "),a("h2",{attrs:{id:"exploring-package-json"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#exploring-package-json"}},[t._v("#")]),t._v(" Exploring package.json")]),t._v(" "),a("p",[t._v("A "),a("code",[t._v("package.json")]),t._v(" file, usually present in the project root, contains metadata about your app or module as well as the list of dependencies to install from npm when running "),a("code",[t._v("npm install")]),t._v(".")]),t._v(" "),a("p",[t._v("To initialize a "),a("code",[t._v("package.json")]),t._v(" type "),a("code",[t._v("npm init")]),t._v(" in your command prompt.")]),t._v(" "),a("p",[t._v("To create a "),a("code",[t._v("package.json")]),t._v(" with default values use:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("npm init "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("yes\n# or\nnpm init "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("y\n\n")])])]),a("p",[t._v("To install a package and save it to "),a("code",[t._v("package.json")]),t._v(" use:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("npm install "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("save\n\n")])])]),a("p",[t._v("You can also use the shorthand notation:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\nnpm i -S {package name}\n\n")])])]),a("p",[t._v("NPM aliases "),a("code",[t._v("-S")]),t._v(" to "),a("code",[t._v("--save")]),t._v(" and "),a("code",[t._v("-D")]),t._v(" to "),a("code",[t._v("--save-dev")]),t._v(" to save in your production or development dependencies respectively.")]),t._v(" "),a("p",[t._v("The package will appear in your dependencies; if you use\n"),a("code",[t._v("--save-dev")]),t._v(" instead of "),a("code",[t._v("--save")]),t._v(", the package will appear in your devDependencies.")]),t._v(" "),a("p",[t._v("Important properties of "),a("code",[t._v("package.json")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"module-name"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"version"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"10.3.1"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"description"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"An example module to illustrate the usage of a package.json"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"author"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Your Name "')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"contributors"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Foo Bar"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"email"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foo.bar@example.com"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bin"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"module-name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./bin/module-name"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scripts"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"test"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"vows --spec --isolate"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"start"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"node index.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"predeploy"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"echo About to deploy"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"postdeploy"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"echo Deployed"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"prepublish"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"coffee --bare --compile --output lib/foo src/foo/*.coffee"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"main"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"lib/foo.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"repository"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"type"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"git"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"url"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/username/repo"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bugs"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"url"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/username/issues"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"keywords"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dependencies"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"express"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"4.2.x"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"devDependencies"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"assume"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"peerDependencies"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"moment"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('">2.0.0"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"preferGlobal"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"private"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"publishConfig"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"registry"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://your-private-hosted-npm.registry.domain.com"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"subdomain"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foobar"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"analyze"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"license"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"MIT"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"files"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"lib/foo.js"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("p",[t._v("Information about some important properties:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("name\n\n")])])]),a("p",[t._v("The unique name of your package and should be down in lowercase. This property is required and your package will not install without it.")]),t._v(" "),a("ol",[a("li",[t._v("The name must be less than or equal to 214 characters.")]),t._v(" "),a("li",[t._v("The name can't start with a dot or an underscore.")]),t._v(" "),a("li",[t._v("New packages must not have uppercase letters in the name.")])]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("version\n\n")])])]),a("p",[t._v("The version of the package is specified by "),a("a",{attrs:{href:"http://semver.org/",target:"_blank",rel:"noopener noreferrer"}},[t._v("Semantic Versioning"),a("OutboundLink")],1),t._v(" (semver). Which assumes that a version number is written as MAJOR.MINOR.PATCH and you increment the:")]),t._v(" "),a("ol",[a("li",[t._v("MAJOR version when you make incompatible API changes\n")]),a("li",[t._v("MINOR version\nwhen you add functionality in a backwards-compatible manner")]),t._v(" "),a("li",[t._v("PATCH\nversion when you make backwards-compatible bug fixes")])]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("description\n\n")])])]),a("p",[t._v("The description of the project. Try to keep it short and concise.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("author\n\n")])])]),a("p",[t._v("The author of this package.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("bin\n\n")])])]),a("p",[t._v("An object which is used to expose binary scripts from your package. The object assumes that the key is the name of the binary script and the value a relative path to the script.")]),t._v(" "),a("p",[t._v("This property is used by packages that contain a CLI (command line interface).")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("script\n\n")])])]),a("p",[t._v("A object which exposes additional npm commands. The object assumes that the key is the npm command and the value is the script path. These scripts can get executed when you run "),a("code",[t._v("npm run {command name}")]),t._v(" or "),a("code",[t._v("npm run-script {command name}")]),t._v(".")]),t._v(" "),a("p",[t._v("Packages that contain a command line interface and are installed locally can be called without a relative path. So instead of calling "),a("code",[t._v("./node-modules/.bin/mocha")]),t._v(" you can directly call "),a("code",[t._v("mocha")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("main\n\n")])])]),a("p",[t._v("The main entry point to your package. When calling "),a("code",[t._v("require('{module name}')")]),t._v(" in node, this will be actual file that is required.")]),t._v(" "),a("p",[t._v("It's highly advised that requiring the main file does not generate any side affects. For instance, requiring the main file should not start up a HTTP server or connect to a database. Instead, you should create something like "),a("code",[t._v("exports.init = function () {...}")]),t._v(" in your main script.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("keywords\n\n")])])]),a("p",[t._v("An array of keywords which describe your package. These will help people find your package.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("devDependencies\n\n")])])]),a("p",[t._v("These are the dependencies that are only intended for development and testing of your module. The dependencies will be installed automatically unless the "),a("code",[t._v("NODE_ENV=production")]),t._v(" environment variable has been set. If this is the case you can still these packages using "),a("code",[t._v("npm install --dev")])]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("peerDependencies\n\n")])])]),a("p",[t._v("If you are using this module, then peerDependencies lists the modules you must install alongside this one. For example, "),a("code",[t._v("moment-timezone")]),t._v(" must be installed alongside "),a("code",[t._v("moment")]),t._v(" because it is a plugin for moment, even if it doesn't directly "),a("code",[t._v('require("moment")')]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("preferGlobal\n\n")])])]),a("p",[t._v("A property that indicates that this page prefers to be installed globally using "),a("code",[t._v("npm install -g {module-name}")]),t._v(". This property is used by packages that contain a CLI (command line interface).")]),t._v(" "),a("p",[t._v("In all other situations you should NOT use this property.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("publishConfig\n\n")])])]),a("p",[t._v("The publishConfig is an object with configuration values that will be used for publishing modules. The configuration values that are set override your default npm configuration.")]),t._v(" "),a("p",[t._v("The most common use of the "),a("code",[t._v("publishConfig")]),t._v(" is to publish your package to a private npm registry so you still have the benefits of npm but for private packages. This is done by simply setting URL of your private npm as value for the registry key.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("files\n\n")])])]),a("p",[t._v("This is an array of all the files to include in the published package. Either a file path or folder path can be used. All the contents of a folder path will be included. This reduces the total size of your package by only including the correct files to be distributed. This field works in conjunction with a "),a("code",[t._v(".npmignore")]),t._v(" rules file.")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://browsenpm.org/package.json",target:"_blank",rel:"noopener noreferrer"}},[t._v("Source"),a("OutboundLink")],1)]),t._v(" "),a("h2",{attrs:{id:"basic-project-definition"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#basic-project-definition"}},[t._v("#")]),t._v(" Basic project definition")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my-project"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"version"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"0.0.1"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"description"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"This is a project."')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"author"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Someone "')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"contributors"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Someone Else"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"email"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"else@example.com"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"keywords"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"improves"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"searching"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("table",[a("thead",[a("tr",[a("th",[t._v("Field")]),t._v(" "),a("th",[t._v("Description")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("name")]),t._v(" "),a("td",[t._v("a "),a("strong",[t._v("required")]),t._v(" field for a package to install. Needs to be lowercase, single word without spaces. (Dashes and underscores allowed)")])]),t._v(" "),a("tr",[a("td",[t._v("version")]),t._v(" "),a("td",[t._v("a "),a("strong",[t._v("required")]),t._v(" field for the package version using "),a("a",{attrs:{href:"https://docs.npmjs.com/getting-started/semantic-versioning",target:"_blank",rel:"noopener noreferrer"}},[t._v("semantic versioning"),a("OutboundLink")],1),t._v(".")])]),t._v(" "),a("tr",[a("td",[t._v("description")]),t._v(" "),a("td",[t._v("a short description of the project")])]),t._v(" "),a("tr",[a("td",[t._v("author")]),t._v(" "),a("td",[t._v("specifies the author of the package")])]),t._v(" "),a("tr",[a("td",[t._v("contributors")]),t._v(" "),a("td",[t._v("an array of objects, one for each contributor")])]),t._v(" "),a("tr",[a("td",[t._v("keywords")]),t._v(" "),a("td",[t._v("an array of strings, this will help people finding your package")])])])]),t._v(" "),a("h2",{attrs:{id:"dependencies"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#dependencies"}},[t._v("#")]),t._v(" Dependencies")]),t._v(" "),a("p",[t._v('"dependencies": {\n"module-name": "0.1.0"\n}')]),t._v(" "),a("ul",[a("li",[a("strong",[t._v("exact")]),t._v(": "),a("code",[t._v("0.1.0")]),t._v(" will install that specific version of the module.")]),t._v(" "),a("li",[a("strong",[t._v("newest minor version")]),t._v(": "),a("code",[t._v("^0.1.0")]),t._v(" will install the newest minor version, for example "),a("code",[t._v("0.2.0")]),t._v(", but won't install a module with a higher major version e.g. "),a("code",[t._v("1.0.0")])]),t._v(" "),a("li",[a("strong",[t._v("newest patch")]),t._v(": "),a("code",[t._v("0.1.x")]),t._v(" or "),a("code",[t._v("~0.1.0")]),t._v(" will install the newest patch version available, for example "),a("code",[t._v("0.1.4")]),t._v(", but won't install a module with higher major or minor version, e.g. "),a("code",[t._v("0.2.0")]),t._v(" or "),a("code",[t._v("1.0.0")]),t._v(".")]),t._v(" "),a("li",[a("strong",[t._v("wildcard")]),t._v(": "),a("code",[t._v("*")]),t._v(" will install the latest version of the module.\n")]),a("li",[a("strong",[t._v("git repository")]),t._v(": the following will install a tarball from the master branch of a git repo. A "),a("code",[t._v("#sha")]),t._v(", "),a("code",[t._v("#tag")]),t._v(" or "),a("code",[t._v("#branch")]),t._v(" can also be provided:\n"),a("ul")]),t._v(" "),a("li",[a("strong",[t._v("GitHub")]),t._v(": "),a("code",[t._v("user/project")]),t._v(" or "),a("code",[t._v("user/project#v1.0.0")])]),t._v(" "),a("li",[a("strong",[t._v("url")]),t._v(": "),a("code",[t._v("git://gitlab.com/user/project.git")]),t._v(" or "),a("code",[t._v("git://gitlab.com/user/project.git#develop")])])]),t._v(" "),a("p",[t._v("After adding them to your package.json, use the command "),a("code",[t._v("npm install")]),t._v(" in your project directory in terminal.")]),t._v(" "),a("h3",{attrs:{id:"devdependencies"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#devdependencies"}},[t._v("#")]),t._v(" devDependencies")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"devDependencies"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"module-name"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"0.1.0"')]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("p",[t._v('For dependencies required only for development, like testing styling proxies ext.\nThose dev-dependencies won\'t be installed when running "npm install" in production mode.')]),t._v(" "),a("h2",{attrs:{id:"extended-project-definition"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#extended-project-definition"}},[t._v("#")]),t._v(" Extended project definition")]),t._v(" "),a("p",[t._v("Some of the additional attributes are parsed by the npm website like "),a("code",[t._v("repository")]),t._v(", "),a("code",[t._v("bugs")]),t._v(" or "),a("code",[t._v("homepage")]),t._v(" and shown in the infobox for this packages")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"main"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"server.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" \n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"repository"')]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"type"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"git"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"url"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"git+https://github.com//.git"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bugs"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"url"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com///issues"')]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"homepage"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com//#readme"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"files"')]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"server.js"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// source files")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"README.md"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// additional files")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"lib"')]),t._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// folder with all included files")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])]),a("table",[a("thead",[a("tr",[a("th",[t._v("Field")]),t._v(" "),a("th",[t._v("Description")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("main")]),t._v(" "),a("td",[t._v("Entry script for this package. This script is returned when a user requires the package.")])]),t._v(" "),a("tr",[a("td",[t._v("repository")]),t._v(" "),a("td",[t._v("Location and type of the public repository")])]),t._v(" "),a("tr",[a("td",[t._v("bugs")]),t._v(" "),a("td",[t._v("Bugtracker for this package (e.g. github)")])]),t._v(" "),a("tr",[a("td",[t._v("homepage")]),t._v(" "),a("td",[t._v("Homepage for this package or the general project")])]),t._v(" "),a("tr",[a("td",[t._v("files")]),t._v(" "),a("td",[t._v("List of files and folders which should be downloaded when a user does a "),a("code",[t._v("npm install ")])])])])]),t._v(" "),a("h4",{attrs:{id:"remarks"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#remarks"}},[t._v("#")]),t._v(" Remarks")]),t._v(" "),a("p",[t._v("You can create "),a("code",[t._v("package.json")]),t._v(" with")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("npm init\n\n")])])]),a("p",[t._v("which will ask you about basic facts about your projects, including "),a("a",{attrs:{href:"https://spdx.org/licenses/",target:"_blank",rel:"noopener noreferrer"}},[t._v("license identifier"),a("OutboundLink")],1),t._v(".")])])}),[],!1,null,null,null);s.default=n.exports}}]);