Registry / web-framework / express-joi-validator

express-joi-validator

JSON →
library2.0.1jsnpmunverified

Express middleware for request validation using the Joi validation library. Version 2.0.1 is the current stable release with no recent updates; it requires joi 6.x.x as a peer dependency. It validates req.query, req.body, and req.params based on Joi schemas, returning Boom errors on failure. Known for its simplicity but limited to Joi v6 and common pitfalls around error handling and required dependencies.

npm install express-joi-validator
INSTALL
IMPORT
SIG · EXPRESS-JOI-VALIDA
E
express-joi-validator
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expressJoi
const expressJoi = require('express-joi-validator');
import expressJoi from 'express-joi-validator';
Plugin uses CommonJS and has no default ESM export; dynamic import is possible but not the default.
default
const expressJoi = require('express-joi-validator');
import * as expressJoi from 'express-joi-validator';
Module exports a single function; namespace import won't work correctly.
validate
const { validate } = require('express-joi-validator');
const validate = require('express-joi-validator').validate;
No named export 'validate' exists; the main export is the middleware function itself.

Express server with GET and POST routes using express-joi-validator for query and body validation.

const express = require('express'); const bodyParser = require('body-parser'); const expressJoi = require('express-joi-validator'); const Joi = require('joi'); const app = express(); app.use(bodyParser.json()); const querySchema = { query: { limit: Joi.number().default(10).min(10).max(100), offset: Joi.number().default(10).min(10).max(100) } }; app.get('/', expressJoi(querySchema), (req, res) => { res.json({ limit: req.query.limit, offset: req.query.offset }); }); const bodySchema = { body: { name: Joi.string().required() } }; app.post('/', expressJoi(bodySchema), (req, res) => { res.json({ name: req.body.name }); }); app.use((err, req, res, next) => { if (err.isBoom) { return res.status(err.output.statusCode).json(err.output.payload); } next(err); }); app.listen(8080);
Debug
Known issues
breakingJoining two Joi versions causes validation failures
fix
Ensure joi peer dependency is 6.x.x exactly; using joi v7+ will break validation.
affects: >=1.0.0 <=2.0.1
deprecatedJoi v6 is outdated and unmaintained; many security fixes in later versions.
fix
Consider migrating to express-validation or use joi v6 with caution.
affects: >=1.0.0 <=2.0.1
gotchaMissing body-parser or express.json() causes empty req.body
fix
Add body-parser.json() middleware before using express-joi-validator.
affects: >=1.0.0 <=2.0.1
gotchaNot catching Boom errors crashes the server on validation failure
fix
Add an express error middleware that checks err.isBoom.
affects: >=1.0.0 <=2.0.1
gotchaSchema structure must be { body, query, params }
fix
Ensure object keys are exactly 'body' or 'query' or 'params'
affects: >=1.0.0 <=2.0.1
Errors
Common errors & fixes
Cannot find module 'joi'
joi is a peer dependency and not automatically installed.
fix
Run: npm install joi@6.x.x
err.isBoom is not a function
Error object is a Boom error from joi, but code tries to call it as a function.
fix
Check err.isBoom as a boolean property, not a method: if (err.isBoom) { ... }
req.body is undefined
Missing body-parser middleware before validation.
fix
Add app.use(bodyParser.json()) before routes.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
joirequiredPeer dependency required for validation schemas
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
express-joi-validator — npm install express-joi-validator · libregistry