node. JS module and NPM Package management tool

Source: Internet
Author: User

in the in Nodejs, a module divides all functions into units and provides a complete module loading mechanism.

module in Nodejs is a very important concept that allows us to introduce third-party class libraries into our applications.

in the in Nodejs you can write or introduce several module files:

1) js script file with suffix . js.

2) A JSON text file with the suffix . json.

3) a compiled binary module file with the suffix. node.

There are two ways to access members within a module outside the module:

1. use The exports object to expose the object. For example:exports.msg=msg; the msg was exposed.

2 . Define the module as a class. For example:module.exports=foo;foo is the exposed class.

Require ("Index.js"); The file is loaded from the Node_modules directory by default .

Properties of the Module object:

Module.id: ID of the current module .

Module.filename: The file name of the current module file.

Module.loaded: boolean value. false indicates that the module is not loaded and True indicates that the module has finished loading.

Module.parent: The parent Module object of the current module.

Module.children: The property value is an array that holds all the submodule objects of the current module, that is, all the module objects that have been loaded in the module.

Note: Nodejs Official Package Warehouse website:http://registry.npmjs.org


This article is from "Time" blog, please make sure to keep this source http://timeblog.blog.51cto.com/8650972/1588755

node. JS module and NPM Package management tool

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.