Loading rules of require method
1. Prioritize loading from cachemain.js: execute and load a.js module require('./a') a.js: executes and loads the b.js module, and outputs that a is loaded require('./b') console.log('a.js is loaded') b.js: Output b is loaded console.log('b.js is loaded') result: It can be seen that: main loads a.js, and then a does not print twice that a.js is loaded when loading b.js. Node will directly take out the exports value of the object from require.cache according to the passed id, and will not execute the module code again. 2. Core Modules
3. Path-based modules
var fooExports = require('./index') //Relative path, commonly used var fooExports = require('../index') //Relative path, commonly used var fooExports = require('/index') //Root directory, not commonly used var fooExports = require('D:/demo/index') //Root directory, not commonly used 4. Third-party modules
Take var template = require('art-template') as an example:
This is the end of this article about the detailed explanation of the loading rules of the require method in node.js. For more relevant content about the loading rules of the node.js require method, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the basic commands of Firewalld firewall in Centos7
>>: Practical method of deleting a row in a MySql table
Currently encountering such a problem My situatio...
background Search the keyword .htaccess cache in ...
Script requirements: Back up the MySQL database e...
The relationship between Tomcat logs A picture is...
Recently, there is a requirement for uploading pi...
Table of contents 1. Introduction 2. JDBC impleme...
Table of contents Preface Basic Usage grammar Err...
Install Follow the README to install The document...
As the computer is used, a lot of garbage will be...
Before introducing the GROUP BY and HAVING clause...
This tutorial shares the installation and configu...
This is a pretty cool feature that makes web page...
Environment: (docker, k8s cluster), continue with...
The so-called three-column adaptive layout means ...
Preface Normally, if we want to delete certain li...