1.0.2 • Published 4 years ago

watch-api v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

watch-api

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install watch-api

API

const logger = require('watch-api')

Middleware Monitoring

With the latest version, you can monitor individual middleware latency. Just use the logger middleware again to indicate the middleware end.

const  express  =  require('express');
const  helmet  =  require('helmet');
const  compression  =  require('compression');
const  logger  =  require('watch-api');

const  app  =  express();

app.use(logger); // place at top to get accurate response time
app.use(helmet());
app.use(logger); // calculates the time spent in helmet middleware
app.use(compression());
app.use(logger); // calculates the time spent in compression middleware

Example

A simple example using watch-api to log api response time and status.

const express = require('express');
const logger = require('watch-api');

const app = express();

app.use(logger); //place at top to get accurate response time

app.get('/foo', function (req, res, next) {
  res.send('Have a good day!');
});

app.get('/bar', function (req, res, next) {
  res.send('Have a good night!')
});

app.listen(3070,()=>{});

Console Output

console output

License

MIT

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago