检查网站是否可以联系

pkb*_*lin 6 node.js npm express

我想检查特定网站是否在线.该网站的名称来自输入字段,并通过邮件发送.

ping主机有一个NPM模块,但这对我没有多大帮助.我需要一个用params检查URL的解决方案,例如:hostname.com/category

我很感激你的建议.

Bra*_*rad 9

只需发出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.

});;
Run Code Online (Sandbox Code Playgroud)