2014-12-06 68 views
5

我想檢查一個特定的網站是否在線。網站的名稱來自輸入字段,並通過郵件發送。檢查網站是否可聯繫

有一個用於ping主機的NPM模塊,但是這對我沒有多大幫助。我需要一個解決方案來檢查網址的參數,如:hostname.com/category

我將不勝感激的建議。

回答

8

只要發出一個HTTP請求。

var http = require('http'); 
http.get('http://example.com/category', function (res) { 
    // If you get here, you have a response. 
    // If you want, you can check the status code here to verify that it's `200` or some other `2xx`. 

}).on('error', function(e) { 
    // Here, an error occurred. Check `e` for the error. 

});; 
+0

謝謝你,這是一個解決方案,幫助我再次 – pkberlin 2014-12-06 20:50:06