npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

morgan-body-ext

v1.2.3

Published

Customised version of morgan-body

Readme

morgan-body-ext

Important Note: The extra functionalities in this library have already been merge to it's parent morgan-body. Thanks!

This library is a customised version of the morgan-body.

The original morgan-body lacks the functionality to log additional request/response tokens like 'Request ID' which would be useful for log tracing purposes.

morgan-body-ext additionally logs these tokens as part of the original log format:

  • id: Request ID

  • request-headers: Request headers (JSON string)

  • response-headers: Response headers (JSON string)

You can also have the option to select only those request/response headers that you want to log by passing in these additional option-parameters:

  • logAllReqHeader: true will log All request headers and take precedence over logReqHeaderList; false otherwise.
  • logReqHeaderList: takes in a list of request headers to be displayed in the log.
  • logAllResHeader: true will log All response headers and take precedence over logResHeaderList; false otherwise.
  • logResHeaderList: takes in a list of response headers to be displayed in the log.

NPM

Example of Use

const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const morganBody = require('morgan-body-ext');

const app = express();

/* Using 'express-request-id' to generate UUID for request 
and add it to X-Request-Id header. 
In case request contains X-Request-Id header, it uses its value instead.
*/
const requestId = require('express-request-id')();

app.use(requestId);

/* Create the 'id' token in morgan that returns the Request ID. 
Refer https://www.npmjs.com/package/morgan#tokens for more details. 
*/
morgan.token('id', req => req.id); 

/* Parse body before morganBody as body will be logged */
app.use(bodyParser.json());

/* Hook morganBody to express app */
morganBody(app, {
  /* logAllReqHeader=true will log All request headers and take precedence over logReqHeaderList */
  logAllReqHeader: false,
  /* logReqHeaderList takes in a list of request headers to be displayed in the log */
  logReqHeaderList: ['host', 'content-length', 'cache-control', 'origin', 'content-type', 'accept'],
  /* logAllResHeader=true will log All response headers and take precedence over logResHeaderList */
  logAllResHeader: false,
  /* logResHeaderList takes in a list of response headers to be displayed in the log */
  logResHeaderList: ['host', 'content-length', 'cache-control', 'origin', 'content-type', 'accept']
});

Example of Generated Logs

2018-09-19T02:32:57.526Z info: [4bc80c25-7748-4fc6-9592-772723333390] Request: POST /sample?test=123 headers[host=localhost:3000;content-length=321;cache-control=no-cache;origin=chrome-extension://aicmkgpgakddgnaphhhpliifpcfhicfo;content-type=application/json;accept=*/*;]
2018-09-19T02:32:57.527Z info: [4bc80c25-7748-4fc6-9592-772723333390] Request Body:{"detail":"123","detail2":{"some-id":"123"}}
2018-09-19T02:32:57.528Z info: [4bc80c25-7748-4fc6-9592-772723333390] Response Body:{"some response body"}
2018-09-19T02:32:57.530Z info: [4bc80c25-7748-4fc6-9592-772723333390] Response: 200 headers[-] 2923.631 ms - 27

References