什么是 url 我可以用来访问我的 express 应用程序 (nodejs)

What is the url with which I can access my expess app (nodejs)

我已经使用 ssh 访问在 GoDaddy 上部署了我的 Nodejs Express 应用程序来配置整个东西。但是我找不到将我带到我的应用程序的 URL。

它在我的电脑上完美运行,我通过 link http://localhost:3000

访问应用程序
const express = require("express");
const bodyParser = require("body-parser");
const httpRequest = require("request");
const app = new express();
const http = require("http").Server(app);
const io = require("socket.io")(http);

app.set("view engine","ejs");

var port = process.env.PORT || 3000;


app.use(express.static("public"));

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//headers
app.use(function (req, res, next) {

// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');

// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, 
PATCH, DELETE');

// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);

// Pass to next layer of middleware
next();
});

app.get("/",(request,response)=>{
 response.send("hello world!");
});


http.listen(port,function(){
 console.log(server.address());
 console.log("listening on port "+port);

});

我有我的服务器的域名,我认为在它的末尾添加“:3000”可以让我访问该应用程序,但显然它不能,我想知道如何访问它。

您可能需要先打开端口。你做这件事的方式取决于你使用什么,使用 Linux-like OS 和你可以做的 ufw

sudo ufw allow 3000

您可以在此处找到更多信息和文档:

ufw - Uncomplicated Firewall

使用您的 GoDaddy 虚拟机的 IP 地址。 按照以下说明找到它:

  1. 登录您的 GoDaddy 帐户。
  2. 在“我的产品”页面中,单击“服务器”。
  3. 在您要使用的服务器旁边,单击“管理”。服务器 IP 地址出现在
  4. 详细信息选项卡。您可能需要向下滚动才能看到列表中的地址。

用法:

http://youripaddress:3000