I really like Node.js and even though it is still not quite a mature technology, it’s pretty stable and usable in production. At this point you can just step in and develop something that hasn’t been done or contribute to Node itself. Today I’m open sourcing Skeleton, my very first contribution to the Node.js community.
Skeleton is an “Express 3.0 framework-less app structure generator”. It really is an itch scratcher for me, so I don’t mind if I end up being the only one using it. There is a basic generator with Express, but I wanted my apps to be in CoffeeScript with a clean object-oriented Rails-like structure.
I kind of had a hard time figuring out how to correctly setup my apps with proper encapsulated require
’s. At first I added all my classes to the global
object, thinking that clearly it has to be the DRYest way to do it. Then I read about why global
is not exactly like the browser’s window
object. Instead, I’m adding them to the app
object, which is kind of the “global scope” in Express anyway.
The only downside is that you have to send app
as an argument when you want to require a module that you want to be globally accessible. I know it’s not really by the encapsulation book per se, but IMO that is fair play considering we cannot safely use global
. Still looking for a valid point on why it would be better to explicitly require all modules again and again in every file. Until then, this is DRY enough for me:
module.exports = (app) ->
class app.ApplicationController
@index = (req, res) ->
res.render 'index',
view: 'index'
# Once this is imported (require), I can use `app.ApplicationController` anywhere
app.get '/', app.ApplicationController.index
I would love to hear about your thoughts/concerns/suggestions on this matter.
Check it out and enjoy!
GitHub Newsfeed Redesign
Good Ol’ Shell Alias To The Rescue