express-server-ping
v1.0.0
Published
Express middleware to check server status and ping remotely
Readme
Express Server Ping
Basic middleware that creates an endpoint to check if the server is running and it's ping.
Params
- Default param for Method is GET
- Default param for Path is /status
Install
$ npm install express-server-statusUsage
To use it with default settings
const serverStatus = require("express-server-ping");
// create the endpoint on GET /status
app.use(serverStatus());To use it on a custom path
const serverStatus = require("express-server-ping");
// create the endpoint on GET /custom_endpoint
app.use(serverStatus({path:'/custom_endpoint'}));Response
The created endpoint will send a response with a json like this {time: 000} where the value is the timestamp when the server received the request.
So to check the ping you can do:
Code from examples/example.js
fetch('https://127.0.0.1/status').then(res => res.json()).then(data => {
const now = Date.now();
const roundtriptime = now - data.time;
console.log(`Server is up | ${roundtriptime} ms`);
}).catch(ex => {
console.log(`Server is down`);
}).finally(() => {
server.close();
});License
MIT ©
