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

request-guardian

v2.0.3

Published

Express middleware that runs express-validator rules from utils/validations/index.js, including per-method rules.

Readme

Request Guardian

request-guardian registers express-validator rules on an Express app. Rules come from your project's utils/validations/index.js. Failed validation returns 422. Unexpected errors while running validators return 400.

Installation

npm install request-guardian
yarn add request-guardian

This package depends on express-validator. Use it with Express.

Usage

Call validate(app) after body parsers such as express.json(), and before you define route handlers. validate attaches middleware when it runs, so calling it after app.post(...) can skip validation.

const express = require('express');
const validate = require('request-guardian');

const app = express();

app.use(express.json());
validate(app);

app.post('/users', (req, res) => {
    // request already passed validation for this path
});

Put validation rules in utils/validations/index.js at the application root (the process working directory), not inside node_modules. Keys must match the Express paths you register.

Each path can be:

  • An array of validation chains: applied to every method (app.use).
  • An object keyed by HTTP method: different rules for GET, POST, and other methods on the same path.

Supported method keys (case-insensitive): all, get, post, put, delete, patch, options, head. Unknown keys are ignored.

Method-specific rules

Use this when the same path needs different rules per method:

// utils/validations/index.js
const { body, query } = require('express-validator');

module.exports = {
    '/api/authentication/signup': {
        GET: [
            query('page').optional().isInt({ min: 1 }),
        ],
        POST: [
            body('email').isEmail(),
            body('password').isLength({ min: 8 }),
        ],
    },
};

all applies to every method on that path, the same as a bare array:

module.exports = {
    '/api/reports': {
        all: [
            query('from').optional().isISO8601(),
        ],
    },
};

Same rules for every method

const { body } = require('express-validator');

module.exports = {
    '/api/users': [
        body('name').notEmpty(),
    ],
};

If a path is not listed, no validation middleware is attached for it. If utils/validations/index.js is missing, validate() logs Validations rules not found at utils/validations/index.js and registers nothing.

Responses

Validation failure:

{
    "data": [],
    "status": "VALIDATION_ERROR",
    "message": "Invalid Data, Validation Failed."
}

data is express-validator's errors.array().

Unexpected error while running validators:

{
    "data": "error message",
    "status": "BAD_REQUEST",
    "message": "error message"
}

HTTP status codes: 422 for validation errors, 400 for other failures in the validator.