So, you need to use the onLoad() callback. Only when that is called is
it assured that the modules are loaded. Otherwise it could be
somewhere in-between.
I think a synchronous module loader could be considered. Web Workers
is doing this. On the other hand, the idea of a purely asynchronous
system is appealing. (At the moment node.debug() is the only
synchronous function.)
> I know you have include() and require(), but to be honest I would much
> rather just load some JavaScript normally and leave 'exporting' to the
> code itself.
>
> This issue somewhat crosses over to views as well, for example this
> would be ideal. Where display() would simply return a parsed view, but
> since everything is callback-crazy I cant really do that
>
> get('article/:id', function(){
> display('article', Article.get(param('id')))
> })
>
> Any ideas?
This should be able to made to work - you'll just need to do a couple
callbacks before finally calling response.finish(). I had a look at
express.core.js and while I haven't spent time time to really look
through it, i can see that
http://github.com/visionmedia/express/blob/651f4abc4741dfe04634fbf1ee0dad8abd85b359/lib/express.core.js#L33
is not going to work except for non-I/O performing requests.
There has to be some callbacks before response.finish() is called.
In node_chat for example, I have requests hold for other I/O
http://github.com/ry/node_chat/blob/0f0296f4183a87f50982fce279838f75921dc40f/server.js#L147
Thinking about your program in terms of I/O events is different and
requires different structure, but somehow, I think it also makes more
sense (it's also massively more efficient)
I agree. It also took me a while to understand how to load the modules
in a specific order (and mimic namespaces as used by node internally,
like node.http.createServer, node.debug, ...).
Though I'm not sure how to really fix it.
Urban