API Reference

avsc

Apache Avro implementation for Node.js with schema types, binary encoding, and container file support.

Official Documentation ↗
CompatibilityThis documentation covers version v5. Check the official docs for the latest API surface.

Installation

npmnpm install avsc
pnpmpnpm add avsc

Methods

Overview

avsc is an Apache Avro implementation for Node.js providing schema types, binary encoding, and container file support. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • Type.forSchema — Compiles an Avro schema into a Type usable for encoding and decoding values.
  • type.toBuffer — Encodes a value to Avro binary using the compiled type.
  • type.fromBuffer — Decodes Avro binary back into a JavaScript value.

Example

const avro = require('avsc');

const type = avro.Type.forSchema({
  type: 'record',
  name: 'User',
  fields: [{ name: 'id', type: 'int' }],
});

Notes

Avro encodes without field names, so decoding requires the schema. Schema evolution relies on reader and writer resolution rules.

Verification

Encode a record, decode it with the same type, and confirm all fields match the original value.

API reference evidence

Fetched from official sources on 2026-11-08T09:38:08.940Z via WebFetch https://raw.githubusercontent.com/mtth/avsc/master/types/index.d.ts.

FAQ

Do writers and readers need the same schema?
They need compatible schemas; Avro supports schema evolution through reader and writer schema resolution.
How do I read Avro container files?
Use avro.createFileDecoder(path), which streams decoded records using the schema embedded in the file header.
How are logical types handled?
Avro logical types annotate primitives; avsc can validate them and map them to JavaScript values when the underlying type is known.