Introduction

Introduction

VineJS is a form data validation library for Node.js. You may use it to validate the HTTP request body in your backend applications.

  • VineJS is one of the fastest validation libraries in the Node.js ecosystem. See benchmarks.

  • It provides both runtime and static type safety.

  • Built for validating form data and JSON payloads. Learn more.

  • Has first-class support for defining custom error messages and formatting errors.

  • Comes with an extensive suite of 50+ validation rules and 12 schema types.

  • Extensible. You can add custom rules and schema types to VineJS. We also make it super easy to test custom validation rules.


import vine from '@vinejs/vine'
const schema = vine.object({
email: vine.string().email(),
password: vine
.string()
.minLength(8)
.maxLength(32)
.confirmed()
})
const data = getDataToValidate()
await vine.validate({ schema, data })

Benchmarks

VineJS is one of the fastest validation libraries in the Node.js ecosystem. Here are the results of validating a simple object with Yup, Zod, and VineJS.

Operations per second (higher is better)

Following is the complete list of various benchmarks on Github, along with their source code and results.

Built for validating form data and JSON payloads

Serializing an HTML form to FormData or a ‌JSON object comes with its own set of quirks. For example:

  • Numbers and booleans are serialized as strings
  • Checkboxes are not booleans
  • And empty fields are represented as empty strings

VineJS handles all these quirks natively, and you never have to perform manual normalization in your codebase.

FAQs

Why should I use VineJS over Zod?

The primary goals of Zod and VineJS are slightly different, and therefore one might be a better fit over the other for a specific use case.

In the case of validating the HTTP request body, VineJS has the following advantages.

  • The performance is 5x-10x better than Zod.
  • VineJS handles many HTML form serialization quirks (which Zod does not).
  • Offers a better workflow for defining custom error messages and formatting errors.

What are the trade-offs of using VineJS?

VineJS is not a generic validation library; therefore, you cannot use it to validate JavaScript data types like Functions, Maps, or Sets.

Can I use VineJS in a front-end application?

VineJS is meant to be used in the backend environment within Node.js runtime. Therefore, you cannot run it inside the browser.

However, if you use Remix or React server components (aka RSC), you can use VineJS as part of your server-side actions.

Who maintains VineJS?

VineJS is an independent open-source project initially created by Harminder Virk and maintained by the AdonisJS core team.

VineJS is an improved version of the existing AdonisJS validator codebase, released as a standalone library to work with any Node.js project.

How can I sponsor VineJS?

The project is funded through Github Sponsors. If you or your business benefit from VineJS, consider sponsoring us to support the project development.

Sponsors