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

aevm

v4.1.1

Published

Another Express Validator Middleware

Readme

Table of Contents

  1. Another Joi validator middleware
    1. Motivation
    2. Getting started
      1. Simple usecase
    3. API
      1. Schema
      2. validate(validationSchema)
      3. paramId(paramName: string)
      4. queryId(paramName: string)
      5. queryString(paramName: string)
      6. getErrorMessage(req, schema)
      7. validateWithResponse(schema)
      8. defaultErrorHandler (DEPRECATED)

Another Joi validator middleware

Motivation

I tired of writing the same code over and over again with validation middlewares for each new project. So I wrote this little package to not repeat myself. The idea is quite simple: it just takes you Joi schema and returns an express middleware that validates it against the data from request object

Getting started

Simple usecase

const Joi = require('joi')
const { validate, defaultErrorHandler } = require('aevm')

const app = require('express')
const router = app.Router()

const schema = {
  body: Joi.object().keys({
    email: Joi.string().email().required(),
    password: Joi.string().min(12).max(80).required(),
    country: Joi.string().default('Ukraine')
  })
}

router.post('/login', validate(schema), (req, res, next) => { /* You code here */ })

app.use('/api', router)

app.use((err, req, res, next) => {
  res.status(err.httpCode || 500).json({ message: err.message })
})

app.listen(3000)

Now if you provide bad data:

{
  "email": "wrong_email",
  "password": "tooshort"
}

It will response with the following error:

{ "message": "'email' must be a valid email" }

Default values specified in schema would be placed in the request object

console.log(req.body.country) // 'Ukraine'

API

Schema

Any validation schema in this package must have the following structure:

interface IUserSchema {
  body?: Joi.ObjectSchema
  query?: Joi.ObjectSchema
  params?: Joi.ObjectSchema
  headers?: Joi.ObjectSchema
}

So basically it's an object with possible keys body, query, params, headers with values of Joi.object().keys() Obviously at least one key is required

validate(validationSchema)

Takes an object with keys body, query, params, headers and values Joi.object().keys() and returns an express middleware that will validate the data and pass an error to next() function if there is any Error would be { httpCode: number, message: string }.

paramId(paramName: string)

Takes a string and creates a schema with a single validation numeric field for the req.params object and returns an express validation middleware Could be usefull for when you need to validate an id from url like GET /users/:userId

queryId(paramName: string)

Takes a string and creates a schema with a single validation numeric field for the req.query object and returns an express validation middleware

queryString(paramName: string)

Takes a string and creates a schema with a single validation string field for the req.query object and returns an express validation middleware

getErrorMessage(req, schema)

Takes a req object and schema and returns error message with default values for custom validation middleware Returned values:

{
  message: 'you error message or empty string',
  values: { /* Object with data from your schema populated with defualt values */ }
}

validateWithResponse(schema)

Takes schema and returns an express middleware that would automatically response with error code 400 end message in JSON like { "message": "your error" }

defaultErrorHandler (DEPRECATED)

The default error handler that could be used to respond with error from middleware that came from validate method