
Designing Singletons in Node.js - fks
http://fredkschott.com/post/2013/12/node-js-cookbook---designing-singletons/
======
moron4hire
I have eventually learned to regret every singleton I've ever written.

~~~
fks
Haha you wouldn't like Node then :)

~~~
moron4hire
It is a thing that bothers me a lot about Node. I much prefer the .NET style
of namespaces over direct file importing, which I could have sworn C taught us
was an antiquated way of doing things. They try to get around it with some
goofiness of "partially loaded files" in the case of A-requires-B-requires-A,
but it smells like a hack and I avoid it at all cost.

That said, it's not necessarily required. You can make any of your module
files export only one function, a function that defines a class. This is the
preferred pattern in most programming languages. I then use dependency
injection to propagate my state around.

And that's generally the case in any programming language: if you're thinking
of a singleton, dependency injection is the answer.

~~~
fks
My next post is on class design in Node. Keep on the lookout, would love to
get your feedback on it.

------
dclara
Nice post. I like it. Thank you.

BTW, do you write javascript to create apps on mobile?

