Node module Management

Source: Internet
Author: User
1/* 2*1: load the module from the node_modules directory; 3 * write to this method: 4 * require ("AA. JS ") 5 * Then node will AA. the JS file is regarded as a file under the node_modules directory 6 * If AA. the absolute path of the JS file is as follows: e: node \ item \ Item1 \ gys \ node_modules \ AA. JS 7 * has an app in the gys folder. JS, which is the same as node_modules. code 10 var name = "guoyansi"; 11 function setname (n) {12 name = N; 13} 14 function getname () {15 return name; 16} 17 exports. getname = getname; 18 exports. setname = setname; 19 // app. JS Code: 20 var AA = require ("AA. JS "); 21 console. log (AA. getname (); 22 AA. setname ("Dr. Sisi"); 23 console. log (AA. getname (); 24/* The result is: 25 * guoyansi26 * Dr. Si 27 */28/* 29 * his search process is like this. 30 * \ node \ item \ Item1 \ gys \ node_modules \ AA. js31 * \ node \ item \ Item1 \ node_modules \ AA. js32 * \ node \ item \ node_modules \ AA. js33 * \ node \ node_modules \ AA. js34 * node_modules \ AA. js35 **/36 // if none of these paths can find the specified file, the system will throw an exception 37 38/* 39*2: use the directory to manage the module 40 * in the node, you can specify the directory name as the module name to manage the module through the directory. You only need to specify an entry point for the directory. 41 * Create the foo folder in the node-modules subdirectory and create the index in Foo. when the following code is used, the index is automatically loaded. JS module 42 * var Index = require ("foo"); 43 * do not want to name the loaded file name index. JS, called myfile. if js44 * is executed, an exception occurs. 45 * You can write this code. 46 * Add a package to the foo folder. JSON file 47 * code: 48*{49 * "Main ":". /myfile. JS "50 *} 51 * is executed in the same way as the preceding 52 **/53 54/* 55 * load module 56 from the global directory if it is in the operating system environment node_path variable, set the variable value to a valid disk directory. When you specify only the module name in the require function, but not the module file path, and node. when JS cannot find the module file to be loaded from other paths, node will find and load the module file from the disk directory specified by the node_path variable. 57 **/

 

Node module Management

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.