Prerequisites
Before installing tsoa, ensure your development environment meets these requirements:Node.js
Node.js version 18.0.0 or higher
TypeScript
TypeScript 5.2.2 or higher
tsoa requires
experimentalDecorators and emitDecoratorMetadata to be enabled in your TypeScript configuration.Package Installation
tsoa is available as npm packages. You can install it using your preferred package manager:Package Breakdown
tsoa consists of multiple packages that work together:@tsoa/cli- Command-line tools for generating OpenAPI specs and routes@tsoa/runtime- Runtime decorators and utilities used in your application codetsoa- Meta-package that includes both CLI and runtime (alternative installation option)
TypeScript Configuration
Configure yourtsconfig.json to enable decorators and emit decorator metadata:
tsconfig.json
Project Structure Setup
Create a recommended directory structure for your tsoa project:tsoa Configuration
Create atsoa.json file in your project root to configure code generation:
tsoa.json
Configuration Options
Entry point of your application. tsoa uses this to find your controllers.
Configuration for OpenAPI specification generation:
outputDirectory: Where to save the generated specspecVersion: OpenAPI version (2 or 3)
Configuration for route generation:
routesDir: Where to generate route filesmiddleware: Framework choice (express,koa, orhapi)
Framework-Specific Installation
Depending on your chosen web framework, install the appropriate dependencies:- Express
- Koa
- Hapi
middleware to "express" in tsoa.json.Build Scripts
Add tsoa generation commands to yourpackage.json:
package.json
Available Commands
tsoa spec
tsoa spec
Generates only the OpenAPI specification file.
tsoa routes
tsoa routes
Generates only the route registration files.
tsoa spec-and-routes
tsoa spec-and-routes
Generates both spec and routes in a single command (recommended).
Verification
Verify your installation by running:Next Steps
Quickstart Guide
Build your first API with tsoa
Controllers
Learn about controller decorators