2016-01-21 51 views
0

我很難過。無法連接到簡單節點上的端口Js服務器

我有一個節點js服務器在子域上運行。

每當我嘗試從瀏覽器訪問它時,我都會收到ERR_CONNECTION_REFUSED錯誤。

這裏是我的服務器代碼

const http = require('http'); 

http.createServer(function (request, response){ 
    response.writeHead(200, {'Content-Type': 'text/plain'}); 
    response.end('Hello World\n'); 
}).listen(8124, "my-server-ip"); 

console.log('Server running at http://127.0.0.1:8124/'); 

附加信息: 我正在與HostGator的一個VPS。 子域與主域共享一個IP;像412.x.xx.xxx。

+0

在控制檯中沒有錯誤,像'createServer被棄用'或什麼? – adeneo

+0

你確定沒有別的東西在使用那個端口嗎? – xkcd149

+0

控制檯中沒有錯誤消息。 – user5819430

回答

0

插入控制檯日誌裏面創建服務器功能。然後你可以找出這個錯誤。你也可以使用錯誤響應。

const http = require('http'); 

http.createServer(function (request, response){ 

    response.writeHead(200, {'Content-Type': 'text/plain'}); 
    response.end('Hello World\n'); 
    console.log('Server running at http://127.0.0.1:8124/'); 

}).listen(8124, "my-server-ip"); 
+0

似乎我根本無法訪問服務器。瀏覽器不斷返回連接拒絕錯誤。我也按照建議使用了console.log - 沒有任何顯示。 – user5819430

相關問題