Nodejs-4.module Modular

Source: Internet
Author: User

1. Introduction of the module:

In a node. JS module system, each file is treated as a standalone module.

2. Module classification:

(1) built-in modules

(2) third-party modules

(3) Custom modules

3. Module use:

(1) Export

(2.1) Module.exports = {}

(2.2) module.exports.xxx = {}

(2.3) exports.xxx = {}

(2) import require ()

Rrequire () can omit the extension when loading the file, it will first load the JS file, if there is no JS file to load the JSON file, and no JSON file to load. node file, so always follow this priority selection, but each require () will only load a file;

4. Module path:

(1) __filename the file name of the current module---the absolute path after parsing.

Console.log (__filename); // C:\Users\xdl\Desktop\test\fs.js

(2) __dirname to get the directory name of the current module.

Console.log (__dirname); // C:\Users\xdl\Desktop\test

Nodejs-4.module Modular

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.