{"id":48233,"library":"joi","title":"Joi","description":"Joi is the most powerful schema description language and data validator for JavaScript. Version 18.2.1 is the current stable release, with regular updates and a comprehensive API for defining schemas using a fluent, chainable syntax. It provides detailed error messages, custom validation, and extensive type support. Joi is widely used for validating API inputs, configuration objects, and form data, and offers a rich plugin ecosystem. It stands out with its expressive API and strong community support.","status":"active","version":"18.2.1","language":"javascript","source_language":"en","source_url":"git://github.com/hapijs/joi","tags":["javascript","schema","validation","typescript"],"install":[{"cmd":"npm install joi","lang":"bash","label":"npm"},{"cmd":"yarn add joi","lang":"bash","label":"yarn"},{"cmd":"pnpm add joi","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v17; CommonJS require() fails in Node 20+.","wrong":"const Joi = require('joi')","symbol":"Joi","correct":"import Joi from 'joi'"},{"note":"Type-only import for TypeScript users.","wrong":null,"symbol":"ObjectSchema","correct":"import { ObjectSchema } from 'joi'"},{"note":"Named export for catching validation errors.","wrong":"const { ValidationError } = require('joi')","symbol":"ValidationError","correct":"import { ValidationError } from 'joi'"}],"quickstart":{"code":"import Joi from 'joi';\n\nconst schema = Joi.object({\n  username: Joi.string().alphanum().min(3).max(30).required(),\n  password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')).required(),\n  email: Joi.string().email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } }).required(),\n  birth_year: Joi.number().integer().min(1900).max(2013),\n  consent: Joi.boolean().valid(true).required()\n});\n\nconst data = {\n  username: 'abc',\n  password: 'mypassword',\n  email: 'abc@example.com',\n  birth_year: 1990,\n  consent: true\n};\n\ntry {\n  const value = await schema.validateAsync(data);\n  console.log('Valid:', value);\n} catch (err) {\n  console.error('Validation error:', err.message);\n}","lang":"typescript","description":"Defines and validates a user object schema with string, number, and boolean fields, demonstrating async validation."},"warnings":[{"fix":"Use import instead of require; upgrade Node to >=12.","message":"Joi v17 drops support for Node.js < 12 and requires ESM imports. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=17.0.0"},{"fix":"Replace .keys() with direct object definition.","message":"Joi.object().keys() is deprecated; use Joi.object() directly.","severity":"deprecated","affected_versions":">=17.0.0"},{"fix":"Upgrade Node to >=20.","message":"Joi v18.2.1 requires Node >= 20. Older Node versions will fail to install.","severity":"gotcha","affected_versions":">=18.0.0"},{"fix":"Use Joi.any().allow(null).allow('') to allow null/empty strings explicitly.","message":"Using Joi.any().allow() with undefined can lead to silent validation errors if not explicitly allowed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use Joi.string().email({ tlds: false }) to allow TLD-less emails if needed.","message":"Joi.string().email() now validates RFC 5321 by default; previously it allowed more lenient formats.","severity":"breaking","affected_versions":">=17.0.0"}],"env_vars":null,"search_vec":"'18.2.1':16 'api':28,54,73 'chainabl':35 'communiti':76 'comprehens':27 'configur':56 'current':19 'custom':42 'data':11,60 'defin':30 'descript':8 'detail':39 'ecosystem':66 'error':40 'express':72 'extens':45 'fluent':34 'form':59 'input':55 'javascript':14,78 'joi':1,2,48 'languag':9 'messag':41 'object':57 'offer':62 'plugin':65 'power':6 'provid':38 'regular':23 'releas':21 'rich':64 'schema':7,31,79 'stabl':20 'stand':68 'strong':75 'support':47,77 'syntax':36 'type':46 'typescript':81 'updat':24 'use':32,51 'valid':12,43,53,80 'version':15 'wide':50","created_at":"2026-06-07T16:55:34.905458+00:00","updated_at":"2026-06-07T16:55:34.905458+00:00","problems":[{"fix":"Change require('joi') to import Joi from 'joi'; or use dynamic import().","cause":"Using CommonJS require() with Joi v17+ which is ESM-only.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/joi not supported."},{"fix":"Use Joi.object({...}).unknown(true) to allow unknown keys, or add the field to the schema.","cause":"The schema does not allow the provided field; often due to .unknown(false) (default) for object schemas.","error":"ValidationError: \"username\" is not allowed. This is a custom error message."},{"fix":"Upgrade to Joi v17+ or use .validate() with callback (deprecated).","cause":"Using an older version of Joi that does not support validateAsync (introduced in v17).","error":"TypeError: Joi.object(...).validateAsync is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/hapijs/joi#readme","github":"git://github.com/hapijs/joi","docs":null,"changelog":null,"pypi":null,"npm":"joi","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}