Re:A Quick Node.js Jumpstart
by nonames on Friday April 08, 2011 @10:58PM
(#2426376)
Not necessarily. The distributed `coffee` script will automatically compile before running the script. Plus it shows you coffeescript-friendly tracebacks on error.
Re:A Quick Node.js Jumpstart
by marcomonteiro on Saturday April 09, 2011 @07:40PM
(#2428412)
Whether I manually compile it or it's automatically compiled it still has to be compiled which was the question I was responding to. Which is to say Node.js will not run CoffeeScript directly.
Re:A Quick Node.js Jumpstart
by checker on Friday April 08, 2011 @02:49PM
(#2425122)
As someone who has read about node but never actually looked at any demo code, this was a pretty good example. Now I understand what all the fuss is about!
Re:A Quick Node.js Jumpstart
by jimmyjazz14 on Friday April 08, 2011 @09:00PM
(#2426165)
One way might be with a closure that wraps the entire module though taking a more OO approach would probably be safer, such as initializing objects with the DB connection as an argument.
http://jashkenas.github.com/coffee-script/
http://wompt.com/chat/nodejs
/* foo.js /
var date = new Date();
exports.Date = date;
/ bar.js /
var foo = require('./foo.js');
exports.Date = foo.Date;
/ foobar.js */
var foo = require('./foo.js');
var bar = require('./bar.js');
console.log(foo.Date);
console.log(bar.Date)
> console.log(foo.Date);
Sat, 09 Apr 2011 01:05:12 GMT
> console.log(bar.Date)
Sat, 09 Apr 2011 01:05:12 GMT
We are dealing with the same date variable between modules.
[edited. not a good place to share code. gist over github: https://gist.github.com/910994]