2017-01-10 37 views
0

我在远程服务器上安装了节点v7.4.0。我已经安装了最新版本的Express,它是4.14.0,我在public_html中设置了index.jsindex.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

也许你的主机阻塞端口? –

+0

使用es5而不是es6来调试 – akinjide

+0

为什么会这样呢? – CreasolDev

回答

1

看起来你的代码没有问题。它可能是防火墙/防病毒软件;此外,请尝试使用其他浏览器,如Firefox。确保使用环回IP 127.0.0.1:3000或localhost:3000(同样的事情)。

0

对我而言,这是因为代理人。禁用Intranet代理后,它工作正常。