Node. js package details _ node. js

Source: Internet
Author: User
This article mainly introduces Node. js package details, Node. A js package is a directory that contains the package in JSON format. json, Node. the js package basically follows the CommonJS specification. For more information, see Node. in js language, packages and modules are not essentially different. packages are further abstracted based on modules. packages encapsulate an independent function, it is used for release, update, dependency management, and version control. Node. js implements the package mechanism according to CommonJS specifications, and develops npm to meet the package release and acquisition requirements.

The Node. js package is a directory containing the package. JSON file in json format. The Node. js package follows the CommonJS specification, so it has the following features:

Package features defined by CommonJS specifications:

1) The top-level directory contains the package. json file;
2) the bin directory stores binary files;
3) the lib Directory stores JavaScript files;
4) store documents in the doc directory;
5) store the unit test in the test Directory.

Node. js modules correspond to files in a one-to-one manner. files can not only be JavaScript source code files or binary files, but also directories. The simplest package is a directory module.

The Node. js package is usually a collection of some modules. It provides high-level abstraction on the basis of the module, which is equivalent to providing some fixed interface function libraries.
By customizing package. json, we can create more complex, more comprehensive, and more compliant packages for release.

Node. when js calls a package, it first checks the package in the package. the main field of the json file, which is used as the interface module of the package. the main field of the json file does not exist, so Node. js will try to find the index. js or index. node is the package interface.

The package. json file is the file used to describe the package in CommonJS specifications. the fully compliant package. json file should contain the following fields:
1) name: Package name. The package name is unique and consists of lower-case letters, numbers, and underscores. it cannot contain spaces.
2) description: Package description. Briefly describe the package.
3) version: version number. The version string that meets the semantic version recognition specification.
4) keywords: a keyword array, usually used for search.
5) maintainers: The maintainer array. Each element contains the name, email (optional), and web (optional) fields.
6) contributors: A contributor array. The format is the same as that of the maintainer array. The package author should be the first element of the contributor array.
7) bugs: The address for submitting a bug. it can be a website or email address.
8) licenses: license array. Each element must contain the type (license name) and url (url linked to the license text) fields.
9) repositories: array of repository hosting addresses. Each element must contain the type (repository type, such as Git), url (repository address), and path (optional) fields.
10) dependencies: package dependency. Is an associated array consisting of the package name and version number.

Note: the semantic version recognition specification is a set of version naming rules proposed by foreign countries. its initial goal is to solve various version number comparison problems and is currently used by many package management systems.

The following is an example of package. json that fully complies with CommonJS specifications:

The code is as follows:


{
"Name": "testpackage ",
"Description": "My package for CommonJS .",
"Version": "0.1.0 ",
"Keywords ":[
"Testpackage ",
"Liq"
],
"Maintainers ":[
{
"Name": "liq ",
"Email": "liq@hotmail.com ",
}
],
"Contributors ":[
{
"Name": "liq ",
"Web": "http://blog.csdn.net/chszs"
}
],
"Bugs ":{
"Mail": "liq@hotmail.com ",
"Web": "http://blog.csdn.net/chszs"
},
"Licenses ":[
{
"Type": "Apache License v2 ",
"Url": "http://www.apache.org/licenses/apache2.html"
}
],
"Repositories ":[
{
"Type": "git ",
"Url": "http://github.com/chszs/packagetest.git"
}
],
"Dependencies ":{
"Webkit": "1.2 ",
"Ssl ":{
"Gnutls": ["1.0", "2.0"],
"Openssl": "0.9.8"
}
}
}

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.