NPM in Package.json detailed

Source: Internet
Author: User

Usually when we use the NPM init command to create a NPM program, a file is automatically generated package.json . The package.json file describes all the information about the NPM package, including the author, profile, package dependencies, build, and so on, in a strict JSON format.

Properties Introduction


nameAnd version is the most important two fields in Package.json, is also the unique identity published on the NPM platform, if these two fields are not set correctly, the package cannot be published and downloaded.


The version number of the package. such as "1.0.0".


The package description information will be displayed in npm search the returned results to help the user select the appropriate package.


The keyword information for the package is an array of strings, as above will also appear in npm search the results.


The home address of the package.


The package's bug tracking home address.


The open source protocol name for the package.


The author of the package.

Contributors, maintainers

The contributor to the package is an array.

Files (Less used)

The package contains all the files that can be taken as folders. Usually we use it .npmignore to remove files that you don't want to include in the package.


The entry file for the package.

bin (Less used)

If your package contains executable files, you can set this field to include them in the system so that you PATH can run them directly and conveniently.

Mans (Less used)

Provides help documentation for the system's man commands. The filename of the Help file must be at the 数字 end, if it is compressed, to the .gz end.

"Man": ["./man/foo.1", "./man/bar.1", "./man/foo.2"]

Directories (Less used)

COMMONJS The directory structure information required by the package, showing the directory structure information for the project. The fields can be: lib, bin, man, Doc, example. The values are all strings.


The warehouse address of the package.

"Repository": {    "type": "Git",    "url": "Git+"   },


By setting this, you can make NPM invoke some command scripts to encapsulate some functionality.

"Scripts": {"start": "Babel-node src/pages/index.js",    "build": "Webpack--config config/ Webpack.config.js ",    " watch ":" Webpack-dev-server--config config/webpack.config.js--hot--inline-- Progress "  }


Add some settings that can be scripts used for reading, and the values will be added to the system's environment variables.

"Config": {  "port": "8080"}

npm startThe environment variable is read npm_package_config_port .


Specify other packages that depend on what is needed when the package is published, that is, the package that is needed on the wire. Use the following command to install:

NPM Install--save PackageName

If you are developing a dependent package, you can devDependencies set it in.


These dependencies are only needed at the time of development. Use the following command to install:


Related dependencies, if your package is a plug-in, and users in the use of your package, usually will also need these dependencies (plug-ins), then you can put the dependency column here.

For example karma , it package.json has settings that depend on the following plugins:

"Peerdependencies": {  "karma-jasmine": "~0.1.0",  "Karma-requirejs": "~0.2.0",  "Karma-coffee-preprocessor": "~0.1.0",  "karma-html2js-preprocessor": "~0.1.0",  " Karma-chrome-launcher ":" ~0.1.0 ",  " Karma-firefox-launcher ":" ~0.1.0 ",  " Karma-phantomjs-launcher ":" ~0.1.0 ",  " Karma-script-launcher ":" ~0.1.0 "}


Bound dependency packages, which are also published when they are published.

optionaldependencies(less used)

Even if these dependencies are not available, they can be installed normally.

engines(less used)

Specifies the environment in which the package runs.

"Engines": {  "node": ">=0.10.3 < 0.12",  "NPM": "~1.0.20"}

os(less used)

Specify which system platforms your package can run under.

"OS": ["Darwin", "Linux", "!win32"]

CPU(less used)

You can specify the CPU architecture that the package runs on.


Set as true This package will not be released to the NPM platform.

publishconfig(less used)

This field is used to set some settings at the time of publishing. Especially handy if you want to set the specified tag or before posting registry .

As follows:

{  "Name": "React",  "Version": "1.0.0",  "description": "Command Line Instructions",  "keywords": [    "React",    "Es6",    "React with ES6"  ],  "Homepage": "Https://",  "Bugs": {    "url": "Https://",    "Email": "[email protected]"  },  "License": "ISC",  "Author": "Zrainna",  "Main": "Src/pages/index.js",  "Directories": {    "Tests": "Tests",    "Lib": "Lib",    "Docs": "Docs"  },  "Repository": {    ' type ': ' Git ',    "url":"Git+"   },  "Scripts": {"Start": "Babel-node src/pages/index.js",    "Build": "Webpack--config config/webpack.config.js",    "Watch": "Webpack-dev-server--config config/webpack.config.js--hot--inline--progress"  },  "Babel": {    "Presets": [      "Es2015-node5"    ]  },  "Devdependencies": {    "Webpack": "^1.13.2",    "Webpack-dev-server": "^1.16.1"  },  "Dependencies": {    "Babel-loader": "^6.2.5",    "babel-preset-es2015": "^6.14.0",    "Babel-preset-react": "^6.11.1",    "React": "^15.3.2",    "React-dom": "^15.3.2",    "React-redux": "^4.4.5",    "React-router": "^2.8.1",    "Redux": "^3.6.0"  }}


NPM in Package.json detailed

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.