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. WAMP虚拟目录的设置

    1.打开Apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#!! 2.打开Apache的apache/conf/extr ...

  2. module

    扯淡的人 http://www.cnblogs.com/yuanchenqi/articles/5732581.html 不被调用的    要写在这下面 1 if __name__=="__ ...

  3. Linux命令(23)grep命令的使用

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...

  4. vuejs,router

    接下来我们要做的是vue的路由处理,首先当然是安装: npm install vue-router 接下打开我们的main.js,引入我们vue-router,然后在告诉vue我们要使用我们的vue- ...

  5. pl/sql配置连接远程数据库oracle,本地没有安装oracle数据库的情况下

    首先下载instantclient 可以到oracle官网下载,要注册账号,一定要下对应版本的,要不然不成功, 10G,11G版的,我已经传上来了,免费下载:正在上传中,稍等 配置文件tnsnames ...

  6. java获取当前日期等以及时区

    代码: public static void main(String[] args) throws Exception{ /* * 获取当前时间的办法 */ //这个获取从1970年..直到现在的毫秒 ...

  7. mysql数据库中如何修改已建好的表中的【列名】【列的属性】

    sql命令:alter table tbl_name change old_col_name new_col_name data_type not null auto_increment primar ...

  8. C#编辑图像文件EXIF信息

    private void setImageTag(string imgFile, string tagFile, string imgTag, string imgTitle) { ; if (Fil ...

  9. Excel with COM

    COM     excelApplication ; COM     workBooks ; COM     workSheets ; COM     workSheet ; COM     work ...

  10. ps基础知识

    一 1. ps常用快捷键:ctrl+d 结束选区    ctrl+alt+z  返回          ctrl+z 撤销           ctrl+x 剪切 ctrl+t 编辑图片    ctr ...