nodejs require

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

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

本人的理解是,ide

  若是文件以"./"开头,则视为当前目录的文件;ui

  若是文件以"/"开头,则视为绝对路径的文件;orm

  其余状况是,先搜索Nodejs的Core Module, 而后搜索本地目录的node_moduls目录. ci

相关文章
相关标签/搜索