node.js - Does anyone have a definitive list of how Node's require paths work? -
i see following...
'./folder/' '../folder/' 'folder/' '/folder/' can explain different path types? there way autosearch folders? refactoring pain!
if exact filename not found, node attempt load required filename added extension of .js, .json, , .node.
.js files interpreted javascript text files, , .json files parsed json text files. .node files interpreted compiled addon modules loaded dlopen.
a module prefixed '/' absolute path file. example, require('/home/marco/foo.js') load file @ /home/marco/foo.js.
a module prefixed './' relative file calling require(). is, circle.js must in same directory foo.js require('./circle') find it.
without leading '/' or './' indicate file, module either "core module" or loaded node_modules folder.
if given path not exist, require() throw error code property set 'module_not_found'.
extracted https://nodejs.org/api/modules.html#modules_file_modules
Comments
Post a Comment