Let's say I have modules A and B which both require a module C.
AFAIK, when running npm install A and npm install B I will get two copies of C automatically installed by NPM in module A and B directories - at least if those modules depend on different versions of C.
I expect that require("C") actually returns different modules for modules A and B.
What if C is meant to exist only once in a Node.JS process, like for example a database connection pooling module, locking mechanism or anything like that? Is this a known "problem"? How should such situations be handled?
Is this a known "problem"?
It is a known solution for a whole set of problems. Usually, you're the one responsible for resources allocation. For example, you open a database connection and pass it (hidden somewhere in DB object) to all dependencies which need a database. Or, you're the one who starts a server which listens for HTTP requests on some port.
Otherwise, if require("C") would return one single copy of that module, it would be a nightmare. Imagine that A requires C version 0.1, while B requires C version 0.1.1. You'll either get an error, or will have to write require('C-0.1.*')-like requires all over the code. A nightmare.