I would go with structure greelgorke suggested. It's less tricky and, IMO,
more structured. I've been writing my modules in the same way
function Mod () {}
Mod.prototype.init = function(){}
module.exports = Mod;
This way you can either have multiple instances of Mod or you can make it a
singleton with something like
var mod = new Mod;
module.exports = mod;
or any other way you like.
On Friday, March 22, 2013 1:50:04 AM UTC-4, Nabeel S. wrote:
>
> Hi all,
>
> I've been meaning to post this up, as it's a pattern I've been using with
> any modules that act as a wrapper to something.
> I just wanted to get some feedback, as I haven't seen this explicitly
> anywhere, and I am curious if I may be causing problems down the line.
>
> I have quite a few apps, which all share a common set of libraries, in a
> package; ie: logging, configuration, database, etc.
> I'll take logging as an example, I use bunyan.
>
> exports.init = function(opts) {
>
> // Do something with options
> // There's a bunch of stuff for different streams to different services
>
> var logger = bunyan.createLogger(...);
> module.exports = logger;
> }
>
> Then in the app initialization:
>
> require('package/lib/logger').init({ ... });
>
> And now in some other module:
>
> var logger = require('package/lib/logger');
>
> logger.debug(...);
>
> Basically replacing the exports with the instance, and then it can be
> called from anywhere, and accessed.
> So my question would be - aside from losing the ability to re-initialize
> (these should theoretically only be initialized once) - is there any
> downside to this pattern; in terms of memory or efficiency?
>
> Nabeel
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.