Re:Your first Node.js module
by radagaisus on Monday May 28, 2012 @04:09AM
(#4032433)
Also, `this` is exported in modules.
[ Parent
| on HN ]
I've noticed that, and have been taking advantage of it. Any downside to using `this`, besides potential scoping issues?
Re:Your first Node.js module
by radagaisus on Monday May 28, 2012 @07:10AM
(#4032859)
Not that I've experienced. Another cool trick: modules make sense when you use packages, but they feel like PHP 4 when you just try to divide your code to several files.
https://gist.github.com/2692091
This fixes part of the problem, but what happens when you reference './models/user.js' from the file 'auth.js' but then auth grows in size and you decide to divide it and put it in auth/facebook.js, auth/twitter.js, etc. -- well, now you are fucked.
You shouldn't require using the extension.
This gives you the flexibility to transparently change the file into a folder + index.*, then break functionality up into pieces that live inside that folder.
Re:Your first Node.js module
by radagaisus on Monday May 28, 2012 @09:35AM
(#4033246)
Still, currently you need to require everything with a relative path unless it's inside node_modules.