Skip to content

A middleware that logs every request on the terminal on development environment

Notifications You must be signed in to change notification settings

cacpmw/requestLoggerMiddleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Request Logger Middleware

Straight forward simple middleware for express server. Logs on terminal every request to the server.

  http POST /account/12?query=somevalue
  http IP ::ffff:127.0.0.1
  http HEADERS {"host":"localhost:3333","user-agent":"insomnia/2022.5.1","content-type":"application/json","accept":"*/*","content-length":"52"}
  http Body {"field1":"Lorem Ipsum","field2":"Lorem Ipsum"}
  http Query {"query":"somevalue"}
  http Params {}
  http Protocol http +9m
  http Response Error {"error":"account already exists"} +31m

Installation

To install simply run: yarn add request-logger-middleware

Usage

On your server file:

const express = require("express");
const requestLoggerMiddleware = require("request-logger-middleware");
const app = express();
app.use(requestLoggerMiddleware());

On your package.json file simply add DEBUG=http to your start up script

"scripts": {
    "dev": "DEBUG=http nodemon src/index.js"
  },

If you want to disable the logger without touching your code simply remove DEBUG=http from your script command. This is specially useful to do when pushing to production since we don't wanna log sensitive information.

Now you should be seeing something like this on your terminal:

screenshot

About

A middleware that logs every request on the terminal on development environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published