nodejs文件引用规则


nodejs文件引用规则

 1、node优先加载核心模块,如http、net、stream等,如果用户自定义模块与node模块全名冲突,则会加载的是核心模块。

 2、如果文件名以"/"、"./"、或"../"打头,则node直接去加载文件,如果没文件,则去加载dir。注意在查找文件的时候,如果失败,会自动给文件加上.js、.json、.node文件。

  

  

 3、如果2依旧失败,则在node_module路径下递归的查找。

  

4、Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:

  • 1: $HOME/.node_modules
  • 2: $HOME/.node_libraries
  • 3: $PREFIX/lib/node

  Where $HOME is the user's home directory, and $PREFIX is Node.js's configured node_prefix.

  It is strongly encouraged to place dependencies in the local node_modules folder. These will be loaded faster, and more reliably.

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM