Hacker News new | ask | show | jobs
by Kiro 3314 days ago
> The module pattern is pretty well known and you can use it to return a singleton.

How would you even make it _not_ return a singleton? I thought that was default.

2 comments

One way is to delete entries from `require.cache`.

Either way you might get a separate instance if npm decided that your module and another module require different version of a given module. These would both be singletons though. Just singletons of instances of different versions of the same module.

It is, I only meant that's a way it can be handled not that it wasn't common or anything.