Installation
Add the package as a dependency:
npm install --save @trapi/metadataPeer Requirements
- Node.js ≥ 22
- TypeScript ≥ 5 — required at runtime because TRAPI drives the TypeScript compiler API to analyse your source. The version from your project is used; TRAPI does not bundle one.
TypeScript is declared as a peer dependency, so your project's typescript version is the one TRAPI will use.
Module Format
@trapi/metadata is an ESM-only package. Your project must either set "type": "module" in package.json or load it via dynamic import() from CommonJS.
Authoring a custom preset?
You don't need @trapi/metadata for that. Install @trapi/core instead — it ships the IR types, handler/preset types, and authoring helpers (controller(...), into, append, flag, readString, …) without pulling in the typescript peer dependency. See Custom Presets.
Bundled With…
You normally install it alongside either @trapi/swagger (if you want OpenAPI output) or a consumer you've written yourself:
# Typical setup
npm install --save @trapi/metadata @trapi/swagger @trapi/preset-decorators-express @decorators/express@decorators/express— runtime decorator library (ortypescript-rest, or your own)@trapi/preset-decorators-express— preset that interprets the chosen decorator vocabulary@trapi/swagger— OpenAPI emitter- The TRAPI marker decorators (
@Hidden,@Tags,@Description,@IsInt, …) are recognised out of the box by both framework presets — no extra package is needed. Write the marker decorators inline yourself or copy fromexamples/decorators
Verify
Once installed, a minimal smoke test:
import { generateMetadata } from '@trapi/metadata';
const metadata = await generateMetadata({
entryPoint: ['src/controllers/**/*.ts'],
preset: '@trapi/preset-decorators-express',
});
console.log(metadata.controllers.length, 'controller(s) discovered');If that runs without errors, continue to Configuration.