[英]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.