I recently came across this article on how to write a singleton in Node.js. I know the documentation of require
states that:
Modules are cached after the first time they are loaded. Multiple calls to
require('foo')
may not cause the module code to be executed multiple times.
So it seems that every required module can be easily used as a singleton without the singleton boilerplate-code.
Question:
Does the above article provide a round about solution to creating a singleton?