Compatible with Any Node JS
Required Node fs library for file operations.
npm i rest-api-logger
This package helps you to record logs of APIs as a middleware.
- Secure
- Easy to use
- Regular Updates
- Neat and clean code
- Commented functions
- Optimized Code
- Records every API log
- Predefined Logging function
- Predefined function to Get Logs
- Clear Logs with
node -e require('rest-api-logger').clearLogs()
- Pagination for Logs
- Logs predefined APIs
https://github.com/bhavneeshgoyal99/Rest-API-Logger-Express-JS-
const http = require("http");
var express = require("express");
var app = express();
const fs = require("fs");
/* Importing Package */
const logger = require("loggers");
/* Adding Middleware */
app.use(logger.logger);
app.get("/", function (req, res) {
res.json({ test: "test" });
res.end();
});
app.get("/logs", function (req, res) {
// Reading logs Here
const logs = logger.readLogs();
res.json(logs);
res.end();
});
app.get("/clear-logs", function (req, res) {
// Clear Logs Here
const logs = logger.clearLogs();
res.end();
});
const port = 4561;
app.listen(port, () => {
console.log("server started at " + port);
});