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
The ogg process of a database produced some time ...
grammar background: linear-gradient(direction,col...
After the image is built successfully, it can be ...
question Recently, when I was completing a practi...
<!DOCTYPE HEML PUBLIC> <html> <hea...
Table of contents 1. Constraint concepts and clas...
Block-level element features : •Always occupies a ...
mysql full backup 1. Enable binary log and separa...
Maybe you are using include files here, which is u...
When the software package does not exist, it may ...
Table of contents splice() Method join() Method r...
Table of contents Project Background Improvement ...
1. Warm and gentle Related address: http://www.web...
During the development process, we often use the ...
After MySQL database optimization, not only can t...