我的远程服务器上安装了节点v7.4.0。我安装了最新版本的快递4.14.0,并在我的index.js
中设置了public_html
。 index.js
是在线官方测试的副本:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (request, response) => {
response.send('Hello from Express!')
})
app.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})
当我在node index.js
中运行public_html
时,我得到了预期的结果:server is listening on 3000
。当我在端口3000上访问我的服务器的域名地址或IP地址时,我只是得到它是“正在连接”然后它失败说它花了太长时间来响应(在命令行中没有响应)。我可以通过什么来解决这个问题?
答案 0 :(得分:1)
您的代码看起来没有任何问题。它可能是防火墙/防病毒软件;另外,尝试使用其他浏览器,如Firefox。确保使用loopback ip 127.0.0.1:3000或localhost:3000(同样的东西)。
答案 1 :(得分:0)
对我来说,这是因为代理。禁用Intranet代理后,它运行正常。