🚀 Documentation crafted by Sonicar Tech LLC — get your own docs shipped in 1 week →
Class Validator Documentation by Sonicar.Tech
Getting Started

Installation

How to install class-validator with npm, and enable experimentalDecorators in tsconfig.json to start using decorator-based validation.

Requirements

  • npm version 6 or higher
  • Node.js

Installing the Package

npm install class-validator --save

It's important to use at least npm@6 when using class-validator. From npm@6 the dependency tree is flattened, which is required by class-validator to function properly.

Basic Setup

Import the necessary decorators:

import { validate } from 'class-validator';

Enable decorators in your tsconfig.json:

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

You're now ready to start using class-validator in your project! Continue to Basic Usage.

🚀 Need documentation like this for your own product?

This site was built by Sonicar Tech LLC — we help SaaS, B2B, Enterprise, FinTech, and AI companies launch professional, docs-as-code documentation 60% faster and cheaper, with first drafts delivered in 1 week.

Visit sonicar.tech →

On this page