The rules of where require finds the files can be a little complex, but a simple rule of thumb is that if the file doesn't start with "./" or "/", then it is either considered a core module (and the local Node path is checked), or a dependency in the local node_modules folder. If the file starts with "./" it is considered a relative file to the file that called require. If the file starts with "/", it is considered an absolute path. NOTE: you can omit ".js" and require will automatically append it if needed. For more detailed information, see the official docs.

Nodejs中的require方法,对文件进行搜索规则如上所述.

本人的理解是,

如果文件以"./"开头,则视为当前目录的文件;

如果文件以"/"开头,则视为绝对路径的文件;

其他情况是,先搜索Nodejs的Core Module, 然后搜索本地目录的node_moduls目录.

nodejs require的更多相关文章

  1. [one day one question] nodejs require 缓存,无法检测文件变化

    问题描述: nodejs require 缓存,无法检测文件变化,当文件require引入后,当文件发生变动后即使再次使用require,返回的依然是第一次引入的文件内容,这怎么破? 解决方案: de ...

  2. nodejs require//////////z

    背景 这篇文基本都是反对的,反对的很有道理,不是说我这篇文章的内容错误,因为这篇文章是我在健身房学习node的时候写的,这些知识都很粗糙,后来发现官方的稳定更详细:地址:http://nodejs.o ...

  3. NodeJS require路径

    项目需要用nodejs,感觉nodejs是前端装逼神器了,是通向全栈工程师的必经之路哇,接下来开始踏上学习nodejs的征程.下面是第一个hello,world的程序. 1.server.js文件,这 ...

  4. nodejs -- require , exports , module

    1. require , exports . -------------------------- 文件: 1) index.js //两种方式都可以: var forExports = requir ...

  5. NodeJS require a global module/package in linux

    https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package 1  export NODE_P ...

  6. 正式学习React(一) 开始学习之前必读

    为什么要加这个必读!因为webpack本身是基于node环境的, 里面会涉及很多路径问题,我们可能对paths怎么写!webpack又是怎么找到这些paths的很迷惑. 本文是我已经写完正式学习Rea ...

  7. vue视频学习笔记03

    video 3 git page:任何仓库 master分支,都可以发布(git page)-------------------------------------双向过滤器:Vue.filter( ...

  8. vue视频学习笔记

    video 7 vue问题: 论坛 http://bbs.zhinengshe.com------------------------------------------------UI组件 别人提供 ...

  9. Webpack vs Browersify vs SystemJs for SPAs

    https://engineering.velocityapp.com/webpack-vs-browersify-vs-systemjs-for-spas-95b349a41fa0 Right no ...

随机推荐

  1. 安装LockBox 3.7.0,用LockBox加密解密!

    LockBox  官  方  网  站:http://lockbox.seanbdurkin.id.au/HomePage LockBox的Github 网址:https://github.com/S ...

  2. shell中bc expr [ ] (( ))的使用方法

    http://blog.chinaunix.net/uid-20671208-id-3552751.html

  3. d3安装异常

    使用npm安装D3,发现其工程名和依赖名重复,导致安装异常 http://thisdavej.com/node-newbie-error-npm-refusing-to-install-package ...

  4. 用delphi实现rar文件的解压的方法

    http://blog.csdn.net/ad_home/article/details/2818936 准备工作     下载winrar提供的动态链接库unrar.dll     http://w ...

  5. java中abstract详解

    Abstract(抽象)可以修饰类.方法 如果将一个类设置为abstract,则此类必须被继承使用.此类不可生成对象,必须被继承使用. Abstract可以将子类的共性最大限度的抽取出来,放在父类中, ...

  6. Android开发-mac上使用三星S3做真机调试

    之前一直未使用真机进行Android开发,为准备明天的培训,拿出淘汰下来的s3准备环境,竟然发现无法连接mac,度娘一番找到答案,如下:mac 系统开发android,真机调试解决方案(无数的坑之后吐 ...

  7. 许小年:宁可踏空,不可断粮<转>

    http://www.daonong.com/g/25/xsqy/2014/0716/51074.html 文│许小年 中欧国际工商学院教授 为什么我们企业的创新能力长期处于低水平呢? 深入观察,内心 ...

  8. BroadCast小结

    1.BroadCast注册方式 静态注册:即在AndroidManifest.xml 文件中定义 <receiver android:name=".BroadCastB"&g ...

  9. 安装和使用elasticsearch

    环境: win7 64位  jdk1.8.0  elasticsearch2.3.3 在官网下载elasticsearch2.3.3:https://www.elastic.co/thank-you? ...

  10. ReactJS学习笔记(二)

    1.Ajax: componentDidMount 方法设置 Ajax 请求,等到请求成功,再用 this.setState 方法重新渲染 UI. /*demo1*/ var Demo1Box=Rea ...