几个node.js进程之间的通信

我有3个node.js应用程序(A,B,C)。 A是一个入口点,我喜欢所有到这个入口点的请求被redirect到B或C(取决于请求中参数的值)。

目前我正在做一个res.redirect在A(我使用expressjs框架)。 这工作正常,但它不是真正透明(我可以从外面看到,原来的请求已被redirect)。

为了解决这个问题,我将B和C监听套接字而不是端口号,但是我不知道如何将请求redirect到B或C使用的套接字。
任何想法如何有2个node.js进程通过套接字进行通信?

**更新**

I have changed the code of A to use node-proxy: app.all('/port/path/*', function(req, res){ // Host to proxied to var host = 'localhost'; // Retrieve port and build new URL var arr_url = req.url.split('/'); var port = arr_url[1]; var new_url = '/' + arr_url.slice(2).join('/'); console.log("CURRENT URL:" + req.url); // url is /5000/test/... console.log("NEW URL :" + new_url); // url is /test/... // Change URL req.url = new_url; var proxy = new httpProxy.HttpProxy(); proxy.proxyRequest(req, res, { host: host, port: port, enableXForwarded: false, buffer: proxy.buffer(req) }); console.log("Proxied to " + host + ':' + port + new_url); // For example: the url is localhost:10000/5000/test // the log tells me 'Proxied to localhost:5000/test' => that is correct // But... I do not get any return // If I issue 'curl -XGET http://localhost:5000/test' I get the return I expect }); 

这有什么明显的错误?

让其他进程在不同的端口上进行侦听,您正处于正确的轨道上。 你在说什么叫做反向代理。 如果它的http,它非常简单地得到这个与node-http-proxy:

https://github.com/nodejitsu/node-http-proxy

你想设置一个像代理表:

 var options = { router: { 'foo.com/baz': '127.0.0.1:8001', 'foo.com/buz': '127.0.0.1:8002', 'bar.com/buz': '127.0.0.1:8003' } }; 

我只是在这里为node-http-rpoxy模块提出一个问题https://github.com/nodejitsu/node-http-proxy/issues/104

显然它现在确实可以和unix套接字一起工作,但是像这样(可能会改变)。

 var options = { router: { 'foo.com/baz': ':/tmp/nodeserver.sock', } }; 

所有它需要的是一个冒号使用套接字path作为端口值。