如何在本地运行的Web服务之间进行通信

我有一些只能通过API网关服务器调用的后端服务。 后端服务在Spring Rest服务中,API GateWay是一个节点服务器。这两个服务器在不同的端口(后端:8080,节点:3000)本地运行。

我如何向我的节点服务器请求后端服务?

如果他们都暴露其余的API,你可以利用内置http模块进行通信

require('http'); var options = { host: 'www.google.com', port: 80, path: '/index.html' }; http.get(options, function(res) { console.log("Got response: " + res.statusCode); res.on("data", function(chunk) { console.log("BODY: " + chunk); }); }).on('error', function(e) { console.log("Got error: " + e.message); }); 

但我会推荐使用superagent或axios这样的库