Node.js's Package details _node.js

Source: Internet
Author: User

In Node.js languages, packages and modules are not fundamentally different, packages are a deeper abstraction on the basis of a module, and packages encapsulate a separate function for publishing, updating, dependency management, and versioning. Node.js implemented the package mechanism according to the COMMONJS specification and developed NPM to solve the package release and acquisition requirements.

The Node.js package is a directory that contains the package description file Package.json in JSON format. The Node.js package basically follows the COMMONJS specification and therefore has the following characteristics:

Package attributes defined by the COMMONJS specification:

1 The top level directory contains Package.json files;
2 The Bin directory is stored in binary files;
3) Lib directory to store JavaScript files;
4 doc directory Storage document;
5) test directory to store unit tests.

Node.js's module and file are one by one corresponding, the file can be not only JavaScript source file or binary file, can also be a directory. The simplest package is the module of a directory.

The Node.js package is usually a collection of modules that provide a higher level of abstraction on the basis of a module, which is equivalent to providing a library of functions with fixed interfaces.
With custom Package.json, we can create more complex, more sophisticated, more compliant packages for publishing.

Node.js when the package is invoked, the main field of the Package.json file in the package is checked first, as the interface module of the package, and if the main field of the Package.json file does not exist, Node.js attempts to find the index.js or Index.node as the interface for the package.

The Package.json file is the COMMONJS specification used to describe the package file, and the fully compliant Package.json file should contain the following fields:
1) Name: Package name. The package name is unique and consists of lowercase letters, numbers, and underscores, and cannot contain spaces.
2) Description: Package description. A brief description of the package.
3 Version: edition number. A version string that satisfies the semantics version identification specification.
4) Keywords: key word group, usually used for search.
5) Maintainers: the maintainer array. Each element contains a name, an email (optional), and a web (optional) field.
6) Contributors: Contributor array. The format is the same as the maintainer array. The package author should be the first element of the contributor array.
7) Bugs: The address of the submitted bug, which can be a web address or an email.
8) Licenses: array of licenses. Each element contains the type (license name) and the URL (the address that links to the license text) field.
9) Repositories: An array of warehouse managed addresses. Each element contains the type (the types of the warehouse, such as Git), the URL (the warehouse address), and the path (the optional) field relative to the warehouse.
Dependencies: Package dependent. is an associative array, consisting of a package name and a version number.

Note: the "Semantic version Identification" specification is a set of version naming norms abroad, the original purpose is to solve a variety of version number size comparison problem, is currently used by many package management systems.

Here is a package.json example that complies fully with the COMMONJS specification:

Copy Code code 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.