Nodejs first entry

Source: Internet
Author: User

Nodejs Module Path

1. Built-in Modules

If passed to require the function is the Nodejs built-in module name, does not do the path resolution, directly returns the internal module the export object, for example: require(‘http‘) .

2. Nodejs supports ( / ) or the absolute path beginning with the drive letter ( C: ), and also supports ./ the relative path at the beginning.

3.nodejs also supports the third path module path node_modules, similar to Foo/bar, loaded can make the file can also be a package, mainly used to store the NPM module.

Example: In an absolute path to a module, when the module is /home/user/app.js loaded in the module require(‘foo/bar‘) , Nodejs attempts to use the following path in turn

/home/user/node_modules/foo/bar    //Node_modules/home/node_modules/foo/bar           //Parent directory under the current directory Node_modules my/ Node_modules/foo/bar    //recursively up and down the path, knowing the Node_modules directory under the root directory

4.node_path Environment variables

Nodejs allows you to specify additional module search paths through the NODE_PATH environment variable, and in general, when customizing the configuration, Node_path points to the global installation directory of NPM settings node_modules

Cases:

Node_path=/home/user/lib:/home/lib

Windows uses comma to divide good Linux

When require(‘foo/bar‘) the module is loaded in the way it is used, Nodejs tries the following path in turn.

/home/user/lib/foo/bar/home/lib/foo/bar

  

Nodejs first entry

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.