{"id":18339,"library":"express-joi-validator","title":"express-joi-validator","description":"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.","status":"maintenance","version":"2.0.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/threadster/express-joi-validator","tags":["javascript","express","joi","middleware","validation"],"install":[{"cmd":"npm install express-joi-validator","lang":"bash","label":"npm"},{"cmd":"yarn add express-joi-validator","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-joi-validator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for validation schemas","package":"joi","optional":false}],"imports":[{"note":"Plugin uses CommonJS and has no default ESM export; dynamic import is possible but not the default.","wrong":"import expressJoi from 'express-joi-validator';","symbol":"expressJoi","correct":"const expressJoi = require('express-joi-validator');"},{"note":"Module exports a single function; namespace import won't work correctly.","wrong":"import * as expressJoi from 'express-joi-validator';","symbol":"default","correct":"const expressJoi = require('express-joi-validator');"},{"note":"No named export 'validate' exists; the main export is the middleware function itself.","wrong":"const validate = require('express-joi-validator').validate;","symbol":"validate","correct":"const { validate } = require('express-joi-validator');"}],"quickstart":{"code":"const express = require('express');\nconst bodyParser = require('body-parser');\nconst expressJoi = require('express-joi-validator');\nconst Joi = require('joi');\n\nconst app = express();\napp.use(bodyParser.json());\n\nconst querySchema = {\n  query: {\n    limit: Joi.number().default(10).min(10).max(100),\n    offset: Joi.number().default(10).min(10).max(100)\n  }\n};\n\napp.get('/', expressJoi(querySchema), (req, res) => {\n  res.json({ limit: req.query.limit, offset: req.query.offset });\n});\n\nconst bodySchema = {\n  body: {\n    name: Joi.string().required()\n  }\n};\n\napp.post('/', expressJoi(bodySchema), (req, res) => {\n  res.json({ name: req.body.name });\n});\n\napp.use((err, req, res, next) => {\n  if (err.isBoom) {\n    return res.status(err.output.statusCode).json(err.output.payload);\n  }\n  next(err);\n});\n\napp.listen(8080);","lang":"javascript","description":"Express server with GET and POST routes using express-joi-validator for query and body validation."},"warnings":[{"fix":"Ensure joi peer dependency is 6.x.x exactly; using joi v7+ will break validation.","message":"Joining two Joi versions causes validation failures","severity":"breaking","affected_versions":">=1.0.0 <=2.0.1"},{"fix":"Consider migrating to express-validation or use joi v6 with caution.","message":"Joi v6 is outdated and unmaintained; many security fixes in later versions.","severity":"deprecated","affected_versions":">=1.0.0 <=2.0.1"},{"fix":"Add body-parser.json() middleware before using express-joi-validator.","message":"Missing body-parser or express.json() causes empty req.body","severity":"gotcha","affected_versions":">=1.0.0 <=2.0.1"},{"fix":"Add an express error middleware that checks err.isBoom.","message":"Not catching Boom errors crashes the server on validation failure","severity":"gotcha","affected_versions":">=1.0.0 <=2.0.1"},{"fix":"Ensure object keys are exactly 'body' or 'query' or 'params'","message":"Schema structure must be { body, query, params }","severity":"gotcha","affected_versions":">=1.0.0 <=2.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install joi@6.x.x","cause":"joi is a peer dependency and not automatically installed.","error":"Cannot find module 'joi'"},{"fix":"Check err.isBoom as a boolean property, not a method: if (err.isBoom) { ... }","cause":"Error object is a Boom error from joi, but code tries to call it as a function.","error":"err.isBoom is not a function"},{"fix":"Add app.use(bodyParser.json()) before routes.","cause":"Missing body-parser middleware before validation.","error":"req.body is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}