News for hackers. Stuff that matters.
Re:A Quick Node.js Jumpstart by abtinf on Friday April 08, 2011 @05:07PM (#2425608)
If folks have node questions, we would be happy to help - wompt is built on node.

http://wompt.com/chat/nodejs

Re:A Quick Node.js Jumpstart by ryanfitz on Friday April 08, 2011 @07:48PM (#2426029)
what is a good way to share something like a db connection between modules?
Re:A Quick Node.js Jumpstart by _pdeschen on Friday April 08, 2011 @09:08PM (#2426182)
I think using require would do the trick. Something along the line like:

/* 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]

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.