---------------------------------------
check /home/somebody/node_modules/othermodule
check /home/somebody/node_modules/othermodule.js
check /home/somebody/node_modules/othermodule.json
check /home/somebody/node_modules/othermodule.node
---------------------------------------
if /home/somebody/node_modules/othermodule/package.json exists
check /home/somebody/node_modules/othermodule/package.json[main]
---------------------------------------
if /home/somebody/node_modules/othermodule/index.js exists
check /home/somebody/node_modules/othermodule/index.js
---------------------------------------
if /home/somebody/node_modules/othermodule/index.node exists
check /home/somebody/node_modules/othermodule/index.node
---------------------------------------
check /home/node_modules/othermodule
check /home/node_modules/othermodule.js
check /home/node_modules/othermodule.json
check /home/node_modules/othermodule.node
---------------------------------------
if /home/node_modules/othermodule/package.json exists
check /home/node_modules/othermodule/package.json[main]
---------------------------------------
if /home/node_modules/othermodule/index.js exists
check /home/node_modules/othermodule/index.js
---------------------------------------
if /home/node_modules/othermodule/index.node exists
check /home/node_modules/othermodule/index.node
---------------------------------------
check /node_modules/othermodule
check /node_modules/othermodule.js
check /node_modules/othermodule.json
check /node_modules/othermodule.node
---------------------------------------
if /node_modules/othermodule/package.json exists
check /node_modules/othermodule/package.json[main]
---------------------------------------
if /node_modules/othermodule/index.js exists
check /node_modules/othermodule/index.js
---------------------------------------
if /node_modules/othermodule/index.node exists
check /node_modules/othermodule/index.node
--------------------------------------- for each $PATH in $NODE_PATH ---------------------------------------
if $PATH/package.json exists
check $PATH/package.json[main]
---------------------------------------
if $PATH/index.js exists
check $PATH/index.js
---------------------------------------
if $PATH/index.node exists
check $PATH/index.node
---------------------------------------
if $HOME/.node_modules/package.json exists
check $HOME/.node_modules/package.json[main]
---------------------------------------
if $HOME/.node_modules/index.js exists
check $HOME/.node_modules/index.js
---------------------------------------
if $HOME/.node_modules/index.node exists
check $HOME/.node_modules/index.node
---------------------------------------
if $HOME/.node_libraries/package.json exists
check $HOME/.node_libraries/package.json[main]
---------------------------------------
if $HOME/.node_libraries/index.js exists
check $HOME/.node_libraries/index.js
---------------------------------------
if $HOME/.node_libraries/index.node exists
check $HOME/.node_libraries/index.node
---------------------------------------
if $PREFIX/lib/node/package.json exists
check $PREFIX/lib/node/package.json[main]
---------------------------------------
if $PREFIX/lib/node/index.js exists
check $PREFIX/lib/node/index.js
---------------------------------------
if $PREFIX/lib/node/index.node exists
check $PREFIX/lib/node/index.node

简单来说,如果是require('x')这样开头不是相对or绝对地址符号,尾巴也没说是.js或者.json的,就当做模块来找。先找是不是core module,然后一级一级向上看node_modules文件夹,每一级的node_modules先看里面是否有basename为所找的文件,再看是否有模块名文件夹下package.json的main标明的文件,然后不死心地看看模块名文件夹下有没有index.js和index.node。最后找不到的话,还要搜一遍全局环境,比如$HOME/.node_modules/什么的。

关于nodejs的require顺序的更多相关文章

  1. [代码]解析nodejs的require,吃豆人的故事

    最近在项目中需要对nodejs的require关键字做解析,并且替换require里的路径.一开始我希望nodejs既然作为脚本语言,内核提供一个官方的parser库应该是一个稳定可靠又灵活的渠道,然 ...

  2. nodejs开发——require与exports的使用

    nodejs开发——require与exports的使用 另一片文章总结:http://www.cnblogs.com/hfultrastrong/p/8036682.html require req ...

  3. nodejs的require模块及路径

    在nodejs中,模块大概可以分为核心模块和文件模块. 核心模块是被编译成二进制代码,引用的时候只需require表示符即可,如(require('net')). 文件模块,则是指js文件.json文 ...

  4. 学会Nodejs 的require和exports

    NodeJs中模块的导入和导出,是最基本的概念,但是看了之后,心里还是有一些疑惑的地方,比如: 1.有两个文件:part.js 和 main.js,main.js中要想使用part.js中定义的变量和 ...

  5. NodeJs中require use get typescript及其他知识点集合

    NodeJs的Express使用 nodejs事件的监听与事件的触发 TypeScript学习笔记 深入浅出Node.js Nodejs开发Office插件 类百度文库文档上传.转换和展示功能项目开源 ...

  6. nodejs的require是如何执行的

    通常,在Node.js里导入是通过 require函数调用进行的. Node.js会根据 require的是相对路径还是非相对路径做出不同的行为. 相对路径 相对路径很简单. 例如,假设有一个文件路径 ...

  7. nodejs中 require 方法的加载规则

    require参数类型 http.fs.path等,原生模块 ./mod或../mod,相对路径的文件模块 /pathtomodule/mod,绝对路径的文件模块 mod,非原生模块的文件模块 在进 ...

  8. nodejs module/require

    1. wrap up a module using module.exports, name the file to a.js var fun1=function(){ var stylus = re ...

  9. nodejs中require的路径是一个文件夹时发生了什么

    node中使用require的时候如果路径是一个文件夹时,或者特殊的情况require('..');require('.'); 这是node实战这本书里说的情况,但是我在node6.9版本中发现不完全 ...

随机推荐

  1. android网络编程之HttpUrlConnection的讲解--GET请求

    1.服务器后台使用Servlet开发,这里不再介绍. 2.测试机通过局域网链接到服务器上,可以参考我的博客:http://www.cnblogs.com/begin1949/p/4905192.htm ...

  2. CentOS7 PostgreSQL 主从配置( 一)

    主库配置 pg_hba.conf host replication all 10.2.0.0/0 trust postgresql.conf listen_addresses = '*' max_wa ...

  3. getReadableDatabase 和 getWritableDatabase的区别

    (1)getWritableDatabase()方法以读写方式打开数据库.一旦数据库的磁盘空间满了,数据库就只能读而不能写,此时用getWritableDatabase()打开数据库就会出错. (2) ...

  4. VG、LV、rezise2fs、lvresize、fuer使用说明

    南沙节点改变LV大小,参考鸟哥第 570页 1.# resize2fs /dev/mapper/vg_niotsvr3-lv_home 150G resize2fs 1.41.12 (17-May-2 ...

  5. nuget pack 时不包含依赖包(而不是引用项目的dll,区别于IncludeReferencedProjects)

    Excluding development dependencies when creating packages Some NuGet packages are useful as developm ...

  6. js监听键盘方向键事件

    <SCRIPT language=javascript> document.onkeydown = chang_page; function chang_page() { || ) loc ...

  7. Asp:Cookies应用指南

    实际上,在web开发中,cookie仅仅是一个文本文件,当用户访问站点时,它就被存储在用户使用的计算机上,其中,保存了 一些信息,当用户日后再次访问这个站点时,web可以将这些信息提取出来.    尽 ...

  8. Road to Cinema

    Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. ActiveX控件在IE中不响应Backspace消息

    1.操作输入法需要导入: #include <imm.h> #pragma comment(lib, "imm32") 2.定义变量: //键盘钩子句柄 HHOOK g ...

  10. merge 语句的语法

    /*Merge into 详细介绍 MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句. 通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询, 连接条 ...