【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.