节点js中一台服务器的连续运行状况检查

时间:2019-04-13 15:00:39

标签: node.js express url server

我要检查在端口8081上运行的另一台服务器上连续运行在8080上的url服务器的运行状况。这是我的代码。

const express = require('express');
const http = require('http');
const app = express();

var url = "http:localhost:8080";
app.get(url, (req, res,request) => {
                res.set({'content-type' : 'application/json; charset=utf-8'});
                res.header({'Content-Type' : 'application/json; charset=utf-8'});
                res.charset = 'utf-8';
                res.header('Access-Control-Allow-Origin', '*');
                console.log("Health check request...");
                res.json({"server" : "Running....", "request" : "Processed", PID: `${process.pid}`,port:`${process.env.PORT}`, code:`${res.statusCode}`,status:`${res.status}`});

});

app.listen(process.env.PORT, ()=>{
    console.log("connection eshtablished to server 2 on 8081");
});

0 个答案:

没有答案