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