Package.json Field Full Solution

Source: Internet
Author: User
Tags node server

Name

must field.

Tips:

    • Do not include the word JS, node in name;
    • This name will eventually be part of the URL, command line parameters, directory names, so you cannot start with a dot or underscore;
    • This name may be called in the Require () method, so it should be as short as possible;
Version

must field.

Description

Optional field, which must be a string. NPM Search will be used.

Keywords

An optional field, an array of strings. NPM Search will be used.

Homepage

Optional field, no URL with protocol prefix such as http://.

Bugs

Optional fields, URL or email address of the problem tracking system,NPM bugs .

{"url": "Http://github.com/owner/project/issues",

"Email": "[email protected]"

}

License

An optional field.

If you are using a common license, such as Bsd-3-clause or MIT, use it directly:

{ "license" : "BSD-3-Clause" }
Author, Contributors

are optional fields. Author is a person, contributors is a group of people.

The author format is as follows:

{ "name" : "Barney Rubble",
 "email" : "[email protected]",
 "url" : "http://barnyrubble.tumblr.com/"
}

This format can also:

"Barney Rubble <[email protected]> (http://barnyrubble.tumblr.com/)"
Files

An optional field that contains a set of files for the project. If it is a folder, the files under the folder will also be included. If you need to include some files that are not included in the project, add a ". Npmignore" file. This file is similar to "Gitignore".

Main

An optional field. The value of this field is the ID ofYour program's main entry module. If other users need your package, when the user calls the Require () method, the export of the module (exports) is returned.

Bin

An optional field. Many packages will have executable files that need to be installed in path.

This field corresponds to a map, and each element corresponds to a {command name: file name}.

{ "bin" : { "npm" : "./cli.js" } }
Directories

The directory structure used to indicate the package:

Directories.lib

Indicates the location of the library file.

Directories.bin

Is the same as the previous bin, but if there is already bin, then this is invalid.

In addition to the above two, there are also directories.doc& Directories.man & Directories.example.

Repository

An optional field. Used to indicate where the code is stored.

"repository" :
  { "type" : "git"
  , "url" : "http://github.com/npm/npm.git"
  }
 
"repository" :
  { "type" : "svn"
  , "url" : "http://v8.googlecode.com/svn/trunk/"
  }
Scripts

Optional field, object. Key is the life cycle event name, and value is the command to run at the event point. Refer to Npm-scripts.

Config

Optional field, object.

The values in the Config object are available throughout the Scripts cycle, specifically to provide configuration parameters for Scripts.

Dependencies

An optional field that indicates the other packages that the current package depends on.

{ "dependencies" :
  { "foo" : "1.0.0 - 2.9999.9999"
  , "bar" : ">=1.0.2 <2.1.2"
  , "baz" : ">1.0.2 <=2.3.4"
  , "boo" : "2.0.1"
  , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
  , "asd" : "http://asdf.com/asdf.tar.gz"
  , "til" : "~1.2"
  , "elf" : "~1.2.3"
  , "two" : "2.x"
  , "thr" : "3.3.x"
  }
}

The version format can be any one of the following:

    • versionExact match
    • >versionGreater than this version
    • >=versionGreater than or equal to this version
    • <version
    • <=version
    • ~versionVery close to this version
    • ^versionCompatible with current version
    • 1.2.xX represents any number, so 1.2.1, 1.2.3, etc. can be
    • http://...The URL of the tarball used under UNIX systems.
    • *Any version is available
    • ""Any version is available
    • version1 - version2Equivalent to >=version1 <=version2 .
    • range1 || range2Meet any one can
    • git...git address
    • user/repo
Devdependencies

An optional field. If you only need to download and use certain modules without downloading the test and documentation frameworks for those modules, it would be nice to put them under this.

Peerdependencies

An optional field. Compatibility dependency. If your package is a plugin, fit this way.

Bundleddependencies

An optional field. Other dependencies that are packaged at the same time as the package is published.

Optionaldependencies

An optional field. If you want to be dependent on some dependencies, even if they are not found, or if the installation fails, NPM continues to execute. Then these dependencies are suitable for putting here.

Engines

An optional field. You can specify either the node version:

{"Engines": {"node": ">=0.10.3 <0.12"}}

You can also specify the NPM version:

{"Engines": {"NPM": "~1.0.20"}}

Enginestrick

Optional field, Boolean value. If you are sure that your program can only be run on the engine that is set to true.

Os

An optional field. Specify what operating system the module can run on:

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

"OS": ["!win32"]

Cpu

An optional field. Specifies the CPU model.

"CPU": ["x64", "IA32"]

"CPU": ["!arm", "!mips"]

Preferglobal

Optional field, Boolean value. If your package is a command-line application that requires a global installation, it can be set to true.

Private

Optional field, Boolean value. If private is TRUE,NPM, the publication will be rejected. This can prevent private repositories from being released accidentally.

Publishconfig

An optional field. The configuration value to use when publishing is put here.

Default value

·"scripts":{"start": "node server.js"}

If you have a server.js file in your package, NPM will do it by default: node server.js .

·"scripts":{"preinstall":"node-gyp rebuild"}

If there is binding.gyp, NPM in the package, the defaultpreinstall命令时,使用node-gyp做编译。

Package.json Field Full Solution

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.