Skip to content

Installation

Requirements

  • npm version 6 or higher
  • Node.js

Installing the Package

npm install class-validator --save

Note

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 than building an in-house team, with first drafts delivered in 1 week.

Visit sonicar.tech