In http://nodejs.org/api/modules.html#modules_all_together the process for module loading is described.
on LOAD_AS_DIRECTORY(X) it says
1. If X/package.json is a file,
a. Parse X/package.json, and look for "main" field.
b. let M = X + (json main field)
c. LOAD_AS_FILE(M)
2. If X/index.js is a file, load X/index.js as JavaScript text. STOP
3. If X/index.node is a file, load X/index.node as binary addon. STOP
It is nice to be able to require a folder name and have it automatically try to load index.js,however when editing multiple modules having multiple index.js files open might become confusing or at least uncomfortable.
I wanted to suggest to add
4. If X/LAST_PATH_FRAGMENT(X).js is a file, load X/LAST_PATH_FRAGMENT(X).jsas JavaScript text. STOP
5. If X/LAST_PATH_FRAGMENT(X).node is a file, load X/LAST_PATH_FRAGMENT(X).node as binary addon. STOP
this way I can name the main js with the same name as the folder and stile just use require('mymodule') and it will load mymodule/mymodule.js.
No comments:
Post a Comment