used for custom logging of apis
npm install watch-apiThis is a Node.js module available through the
npm registry. Installation is done using thenpm install command:
``sh`
$ npm install watch-api
`js`
const logger = require('watch-api')$3
With the latest version, you can monitor individual middleware latency. Just use the logger middleware again to indicate the middleware end.
`js
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
`
A simple example using watch-api to log api response time and status.
`js
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,()=>{});
``