Detailed description of the package file package.json

Package description file

Package description files for the expression of non-code information relating to it is a JSON format file --package.json, located under the root directory of the package, it is an important part of the package. And all acts are closely related field npm package description files.

CommonJS must define the field package.json file.

  1. name: the package name. It requires specification defines the composition of lowercase characters and numbers, may contain \ _ and -, but spaces are not allowed. Package name must be unique in order to avoid misunderstanding of the same name conflict when announced. In addition, NPM also recommended not incidental to the node js or repeat indicate that it is a JavaScript or Node module in the package name.
  2. description: Introduction package.
  3. version: version number.
  4. keywords: Keywords array, NPM is mainly used for classification search. A good keyword array help users quickly find the package you write.
  5. maintainers: package maintainer list, each of the maintainer by the name, email and web three attributes.

NPM carried out by the certification authority property.

  1. contribuctors: a list of contributors.
  2. bugs: a can of bug feedback page address or email address.
  3. licenses: a list of the current license used by the package, indicating that the package uses in which a license.
  4. repositories: hosting the source code for a list of locations to indicate which way and address the source code can access the package through.
  5. dependencies: List Packet using current package depends. This property is very important, NPM will automatically load the package using this property.

In addition to mandatory field, the specification also defines part of an optional field

  1. homepage: website address of the current package.

  2. os: a list of operating systems supported. The value of these operating systems include aix, freebsd, Linux, macos, solaris, vxworks, windows. If the setting list is empty, no operating system to make any assumptions.

  3. CPU: Support List CPU architecture.

  4. engine: Supported js engine list, a list of valid values ​​include engine ejs, flusspferd, gpsee, jsc, spidermonkey, narwhal, node, v8.

  5. builtin: flag whether the current packet is built into the standard component in the underlying system.

  6. directories: Package catalog description.

  7. implements: achievement of a standardized list, mark the current package that implements the specification CommonJS.

  8. scripts: Script description of the object. It is mainly used to install the package manager, compiling, testing and unloading packages.

    //示例如下:
    "scripts":{
    	"install":"install.js",
    	"uninstall":"uninstall.js",
    	"build":"build.js",
    	"test":"test.js"
    }
    

Define package specification can help solve the problem Node dependencies installed, while NPM is based on the specification implementation. Initially, NPM tools are there Issac Z.Schlueter create a separate, provided to the Node Package Manager node services, need to be installed separately. Later, when integrated into the Node v6.3 version as the default package manager, as part of the installation package together.

Described in the specification file in the package, NPM actual field needs mainly name, version, description, keywords, repositories, author, bin, main, scripts, engines, dependencies, devDependencies.

The difference between the packet specification is more author, bin, main and devDependencies four fields.

author: Package authors.

bin: Some package authors hope that the package can be used as a command line tool. After configuring the bin field, by npm install package_name -gcan be added to the script command execution path, then you can execute directly on the command line. -G command module by mounting the package called global model.

main: module introduction method require () when introduced into the package, checks the priority field, and as the remaining modules in the package inlet. If the field does not exist, require () method looks index.js in the package directory, index.node, index.json file as the default entry.

devDependencies: Some modules only need to rely on in the development. This configuration attribute, the developer may be prompted subsequent installation package dependencies.

//以下是node比较有名的框架express项目的package.json文件
{
  "name": "express",
  "description": "Fast, unopinionated, minimalist web framework",
  "version": "4.17.1",
  "author": "TJ Holowaychuk <[email protected]>",
  "contributors": [
    "Aaron Heckmann <[email protected]>",
    "Ciaran Jessup <[email protected]>",
    "Douglas Christopher Wilson <[email protected]>",
    "Guillermo Rauch <[email protected]>",
    "Jonathan Ong <[email protected]>",
    "Roman Shtylman <[email protected]>",
    "Young Jae Sim <[email protected]>"
  ],
  "license": "MIT",
  "repository": "expressjs/express",
  "homepage": "http://expressjs.com/",
  "keywords": [
    "express",
    "framework",
    "sinatra",
    "web",
    "rest",
    "restful",
    "router",
    "app",
    "api"
  ],
  "dependencies": {
    "accepts": "~1.3.7",
    "array-flatten": "1.1.1",
    "body-parser": "1.19.0",
    "content-disposition": "0.5.3",
    "content-type": "~1.0.4",
    "cookie": "0.4.0",
    "cookie-signature": "1.0.6",
    "debug": "2.6.9",
    "depd": "~1.1.2",
    "encodeurl": "~1.0.2",
    "escape-html": "~1.0.3",
    "etag": "~1.8.1",
    "finalhandler": "~1.1.2",
    "fresh": "0.5.2",
    "merge-descriptors": "1.0.1",
    "methods": "~1.1.2",
    "on-finished": "~2.3.0",
    "parseurl": "~1.3.3",
    "path-to-regexp": "0.1.7",
    "proxy-addr": "~2.0.5",
    "qs": "6.7.0",
    "range-parser": "~1.2.1",
    "safe-buffer": "5.1.2",
    "send": "0.17.1",
    "serve-static": "1.14.1",
    "setprototypeof": "1.1.1",
    "statuses": "~1.5.0",
    "type-is": "~1.6.18",
    "utils-merge": "1.0.1",
    "vary": "~1.1.2"
  },
  "devDependencies": {
    "after": "0.8.2",
    "connect-redis": "3.4.1",
    "cookie-parser": "~1.4.4",
    "cookie-session": "1.3.3",
    "ejs": "2.6.1",
    "eslint": "2.13.1",
    "express-session": "1.16.1",
    "hbs": "4.0.4",
    "istanbul": "0.4.5",
    "marked": "0.6.2",
    "method-override": "3.0.0",
    "mocha": "5.2.0",
    "morgan": "1.9.1",
    "multiparty": "4.2.1",
    "pbkdf2-password": "1.2.1",
    "should": "13.2.3",
    "supertest": "3.3.0",
    "vhost": "~3.0.2"
  },
  "engines": {
    "node": ">= 0.10.0"
  },
  "files": [
    "LICENSE",
    "History.md",
    "Readme.md",
    "index.js",
    "lib/"
  ],
  "scripts": {
    "lint": "eslint .",
    "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/",
    "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",
    "test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"
  },
  "__npminstall_done": "Sun Feb 16 2020 11:22:54 GMT+0800 (GMT+08:00)",
  "_from": "[email protected]",
  "_resolved": "https://registry.npm.taobao.org/express/download/express-4.17.1.tgz"
}

NPM common functions

Published 27 original articles · won praise 5 · Views 6111

Guess you like

Origin blog.csdn.net/systempause/article/details/104340440