I spied in some code the following:
var Log = require('log');
// This creates a singleton instance
module.exports = new Log('info');
My first reaction was "no way that is a singleton", but I remember an article that outlined how Node.js does require()
statements said something about caching require statements and using them in subsequent calls.
So basically my question, is exporting a new Object()
actually creating a singleton behind the scenes?
I know there are other ways of creating singletons in JavaScript, but this seems like a pretty handy way of doing it inside Node (if it actually works).