![](/img/trans.png)
[英]apache2 / nodejs / express on a digital ocean server - how to listen to public port (80) without address in use error
[英]How to listen on my public IP address port using Nodejs
我希望使用公共IP地址而不是本地主机访问Nodejs应用程序。 现在要在本地主机上托管我的应用程序:
app.listen(process.env.PORT||9000,()=>{
console.log('Server is running on 9000!')
})
我想设置Nodejs与Nodejs的通信。 我从stackoverflow获得了帮助,并使用npm request
包将发布请求从运行在端口3000上的一台nodejs服务器发送到运行在端口9000上的一台发布服务器
const request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:9000/',
headers: { 'Content-Type': 'application/json' },
body: { id: 1 },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
// console.log(body);
// Process the body and return the response.
// return res.send(body);
});
但是,我想使用公共IP地址,因为我想在Heroku上托管我的一台服务器。 我将需要公共IP地址来创建通信
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.