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

express-logging-json

v0.0.3

Published

A JSON logging helper for Express

Readme

express-logging-json

A JSON logging helper for Express

Installation

npm install express-logging-json

Usage

A simple logging middleware example, with on-finished module:

const onFinished = require('on-finished');
const format = require('express-logging-json');

const options = {
    mask: {
        fields: ['headers.authorization']
    }
};

const app = express();

app.use((req, res, next) => {
    onFinished(res, err => {
        const log = format(req, res, options);
        log.err = err;
        console.info(log);
    });
    next();
});

Leaving parts out

A log refers to a lot of what a request carries, and an access log is written for every request. To log less, leave out what is not needed with omit: paths, or regular expressions tested against them.

const options = {
    omit: [
        'trailers', // a top-level key
        'headers.accept-language', // a path
        /^headers\.sec-/ // everything a regular expression matches
    ]
};

Paths are dotted, as in mask.fields. The items of an array share the path of the array, so items.note leaves out note in every item. Like masking, it works on a copy and never changes the request. It can be combined with mask.

Masking secrets

A request log refers to everything a request carries: headers, cookies, session, query, body. Secrets in there are easy to miss, so masking can be done by path, by name or by what a value looks like. Masking works on a copy: the request, session and response are never changed.

const options = {
    mask: {
        fields: ['body.card.number'], // an exact path
        keys: ['pin', /^x-internal-/i], // names, at any depth
        values: [/\b\d{16}\b/], // matches within any string
        auto: true, // the names and shapes that most secrets have, see below
        except: [/^x-token-/i] // names that only sound secret, see below
    }
};

auto masks:

  • keys named like secrets, as whole words: password, secret, token, credentials, authorization, signature, jwt, csrf, api key, session id and the like, in any style (x-auth-token, csrfSecret, API_KEY), and the Cookie and Set-Cookie headers. Words that merely contain these letters, such as passport or author, are left alone
  • the values of those keys, unless there is nothing to hide: flags, nulls, and cookie objects that are only settings
  • recognisable secrets in any string, whatever the key is called: JSON web tokens, the credentials of Bearer and Basic values, well known vendor keys, PEM private keys, and secret-looking query parameters such as token or signature, as in a url

Only the secret part is replaced, so Bearer [Filtered] and ?signature=[Filtered]&page=2 stay readable. Long hex or base64 strings are not treated as secrets: they are at least as often ids.

A name can sound secret and hold something harmless, such as an id in a token-user header. List those in except and auto leaves them alone by name. What is inside is still checked, so a real token in an excepted header is masked all the same. keys and fields take precedence over except.

Masking is a safety net, not a guarantee. A secret under an innocent name, in an unrecognisable shape, is not found.

The same helpers can be used on other parts of a log, such as a text line:

const { redact, redactString, secrets } = require('express-logging-json');

redactString('GET /file?signature=abc123 HTTP/1.1', { auto: true });
// 'GET /file?signature=[Filtered] HTTP/1.1'

redact(anyObject, { auto: true, except: ['x-token-user'] }); // a masked copy
secrets.isSecretKey('x-api-key'); // true