Comparing version 1.0.3 to 1.0.4
@@ -12,4 +12,13 @@ "use strict"; | ||
// app.use(express.urlencoded({extended:true})) | ||
// const parameters = { | ||
// time: true, | ||
// method: true, | ||
// path : true, | ||
// query : true, | ||
// body : true | ||
// } | ||
// // an array of paths you want the logger to ignore | ||
// const ignore_urls = ['/a', '/b'] | ||
// // logs the request data to console in table form | ||
// const RL = new RequestLogger({ignore_urls : ['/logs'],showLatestFirst : false}) | ||
// const RL = new RequestLogger({ignore_urls,parameters,showLatestFirst : false}) | ||
// const router = express.Router() | ||
@@ -19,2 +28,5 @@ // router.all('/', (req:Request, res:Response) : void => { | ||
// }) | ||
// router.all('/another',(req:Request, res:Response) : void => { | ||
// res.send("Hello world") | ||
// }) | ||
// app.use(RL.Console()) | ||
@@ -21,0 +33,0 @@ // app.use(RL.Webpage({url : '/logs'})) |
{ | ||
"name": "reqlogs", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A simple logger, which logs the request to server in form of tables, it helps to debug the connection with client and can also be used for metrics.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,72 @@ | ||
# Express-Request-Logger | ||
A library to log the requests data for debugging connection with frontend , testing and monitoring purposes | ||
# *REQLOGS* | ||
A library to log the HTTP requests coming to the server for debugging, testing and monitoring purposes. | ||
<hr> | ||
It acts as a middleware and logs the request data in form of table in console and render it in form of bootstrap tables, everytime a request comes. | ||
This solves the problem of debugging by console logging request data manually everytime a route doesn't work. | ||
### Installation | ||
This is mostly useful for debugging purposes, so to install it as a dev-dependency you can simply install the npm package with dev flag. | ||
```sh | ||
npm install --save-dev reqlogs | ||
``` | ||
### How to use and configure | ||
``` | ||
const express = require('express') | ||
const app = express() | ||
const PORT = process.env.PORT || 8081 | ||
// import the library | ||
const {RequestLogger} = require('reqlogs') | ||
// select the parameters you want to log from the HTTP request. | ||
const parameters = { | ||
time: true, | ||
method: true, | ||
path : true, | ||
query : true, | ||
body : true | ||
} | ||
// an array of paths you want the logger to ignore | ||
const ignore_urls = ['/a', '/b'] | ||
// a boolean (optional) , for ordering of the data in table logs | ||
const showLatestFirst = true | ||
// create an object and pass the parameters | ||
const RL = new RequestLogger({ignore_urls, parameters, showLatestFirst}) | ||
// essential middleware... | ||
app.use(express.json()) | ||
app.use(express.urlencoded({extended:true})) | ||
. | ||
. | ||
. | ||
// put RL middlewares at the bottom just above the routes/api | ||
app.use(RL.Console()) | ||
// specify the url for the webview | ||
const url = '/logs' | ||
app.use(RL.Webpage({url})) | ||
app.use(API) | ||
app.listen(PORT, () => { | ||
console.log(`Server started at port : ${PORT}`) | ||
}) | ||
``` | ||
> Tip : This will work only if your server already has the required middlewares setup before the reqlogs middleware like cookies-parser for cookies and express.json() for body etc. | ||
### Working | ||
This will log your request data in form of tables in console and will render a webview as well. | ||
Webview for an example server | ||
![web-view](./docs/ss/web.png) | ||
Console for an example server | ||
![console-view](./docs/ss/console.png) | ||
[NPM](https://www.npmjs.com/package/reqlogs) |
@@ -11,4 +11,13 @@ // import express , {Request, Response} from 'express' | ||
// const parameters = { | ||
// time: true, | ||
// method: true, | ||
// path : true, | ||
// query : true, | ||
// body : true | ||
// } | ||
// // an array of paths you want the logger to ignore | ||
// const ignore_urls = ['/a', '/b'] | ||
// // logs the request data to console in table form | ||
// const RL = new RequestLogger({ignore_urls : ['/logs'],showLatestFirst : false}) | ||
// const RL = new RequestLogger({ignore_urls,parameters,showLatestFirst : false}) | ||
@@ -22,2 +31,5 @@ | ||
// router.all('/another',(req:Request, res:Response) : void => { | ||
// res.send("Hello world") | ||
// }) | ||
@@ -24,0 +36,0 @@ // app.use(RL.Console()) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197432
26
510
73