これがばかげた質問である場合はお詫びしますが、両方を必要とする2つのモジュールと、両方のモジュールを必要とするメインアプリケーション、または両方のモジュールを必要とするモジュールを作成し、それ自体に「http」を必要とする場合目的のために、httpモジュールの3つのインスタンスがあり、それぞれが異なるクロージャーのスコープ内でロックされているのでしょうか、それともノードはこれを回避するために物事を書き直しているのでしょうか?
言い換えれば、私は次のようなアプリになってしまいますか?
// main app creates a closure containing a local instance of http, an instance of proxy1
// and an instance of proxy2, both of which are functions returned from closures that have instances of http in scope
var http = require('http'),
httpProxy1 = require('./proxy1'),
httpProxy2 = require('./proxy2');
/* ... do stuff with http, using proxy1 or proxy2 where appropriate ... */
// proxy1 creates a closure containing a local instance of http and exposes a single public method
var http = require('http');
module.exports = function (foo) { /* ... do stuff with http ... */ }
// proxy2 creates a closure containing a local instance of http and exposes a single public method
var http = require('http');
module.exports = function (foo) { /* ... do stuff with http that has nothing to do with the stuff proxy1 does ... */ }
proxy1も独立して使用したい場合は、モジュールとして使用するのが理にかなっていますが、小さなプロジェクトでも、コアモジュールを繰り返し必要とする多くのモジュール(特にhttpとfs)が発生する可能性があります。