Validation5M+/wkBSD-3-Clause

joi

Joi is the most powerful schema description language and data validator for JavaScript, originally created as part of the Hapi.js framework ecosystem. Joi provi

Installation

npm
npm install joi
yarn
yarn add joi
pnpm
pnpm add joi

Import

ESM
import Joi from 'joi';

Quick Example

usage
import Joi from 'joi';

const schema = Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  email: Joi.string().email().required(),
  password: Joi.string().pattern(/^[a-zA-Z0-9]{8,}$/),
  role: Joi.string().valid('admin', 'user').default('user'),
});

const { error, value } = schema.validate({
  username: 'alice', email: '[email protected]', password: 'Pass1234',
});

About joi

Joi is the most powerful schema description language and data validator for JavaScript, originally created as part of the Hapi.js framework ecosystem. Joi provides an extremely comprehensive API for describing data schemas with over 100 validation methods covering strings, numbers, dates, arrays, objects, alternatives, binary data, and symbols. The library supports complex validation scenarios including conditional requirements (.when()), forbidden fields, field references (validating one field relative to another), recursive schemas, custom validation functions, and detailed error messages with full path information. Joi's string validators include email, URI, IP address, GUID, credit card, ISO date, and regex patterns. Object schemas support .and() (all or none), .or() (at least one), .xor() (exactly one), .with() (if A then B), and .without() (if A then not B) for complex field relationships. Joi handles type coercion, default values, stripping unknown keys, and renaming keys during validation. While Joi was designed for Node.js server-side validation and is heavier than browser-focused alternatives, its unmatched validation power makes it the go-to choice for complex API input validation, configuration file validation, and data pipeline verification.

Quick Facts

Packagejoi
CategoryValidation
Weekly Downloads5M+
LicenseBSD-3-Clause
Installnpm install joi

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.