Nestia CLI Tool
Nestia is a comprehensive CLI tool designed to enhance NestJS development by providing a suite of features including super-fast decorators, advanced WebSocket routes, and robust code generation capabilities. It currently stands at version 11.0.2 and receives active development, with frequent releases addressing features, bug fixes, and minor breaking changes. A key differentiator is its deep integration with `typia` for runtime validation and JSON serialization, which claims significantly higher performance (e.g., 20,000x faster than `class-validator` for validation, 200x faster than `class-transformer` for serialization). Nestia also generates a fully typed SDK for clients, complete with a mockup simulator and E2E test functions, akin to `tRPC` but with a focus on code generation rather than direct RPC, and offers advanced Swagger document generation features including AI chatbot integration. Its modular design includes sub-packages like `@nestia/core`, `@nestia/sdk`, and `@nestia/e2e` for specific functionalities.
Common errors
-
Error: Command 'sdk' is not registered.
cause Attempting to run a Nestia command that is not recognized by the current version or installation.fixEnsure `nestia` is installed correctly via `npm install -D nestia` or `yarn add -D nestia`. Verify the command exists in your `package.json` scripts or is called directly via `npx nestia <command>`. -
Error: Configuration file "nestia.config.ts" not found.
cause Nestia CLI commands, especially `sdk` or `swagger`, require a configuration file, typically `nestia.config.ts`, in the project root.fixCreate `nestia.config.ts` in your project root. You can generate a basic one with `npx nestia init --project tsconfig.json`. -
TypeError: (0, _nestia_sdk__WEBPACK_IMPORTED_MODULE_0__.is) is not a function
cause This often indicates an issue with Typia's runtime validation setup, where the `is` function (or similar `typia` functions) is not correctly imported or bundled.fixEnsure `typia` is installed (`npm install typia`) and that your `nestia.config.ts` correctly configures Typia. Verify your `tsconfig.json` includes the necessary settings for transformer plugins if applicable. -
TS2307: Cannot find module '@nestia/core' or its corresponding type declarations.
cause The `@nestia/core` package is not installed or TypeScript cannot locate its type definitions.fixInstall `@nestia/core` as a dependency: `npm install @nestia/core` or `yarn add @nestia/core`. Ensure your `tsconfig.json` includes `node_modules/@nestia/core` in its `include` or `types` paths, though this is usually handled automatically.
Warnings
- breaking The way Typia validates programmers has changed in v11.0.0. This may require adjustments to existing validation logic or configurations when upgrading.
- breaking In v10.0.1, the SDK generator changed the escape symbol from `$` to `_` for generated client symbols to avoid conflicts. If your client code or generated files relied on the `$` symbol, they will break.
- breaking Nestia v10.0.0 introduced a 'universal LLM schema' feature. This likely entails changes to how LLM-related schemas are generated or configured within Nestia, potentially breaking existing AI Chatbot integrations.
- gotcha Nestia is a code generator. Re-running generation commands (e.g., `nestia sdk`) can overwrite existing files within the target SDK or Swagger output directories. Ensure you manage custom code in separate files or use appropriate configuration options to prevent accidental overwrites.
- gotcha Nestia's performance claims (e.g., '20,000x faster than class-validator') are based on specific benchmarks against alternative libraries. While generally faster, actual performance gains in your application depend on your specific workload, data structures, and usage patterns. Proper setup and configuration are critical to realize these benefits.
Install
-
npm install nestia -
yarn add nestia -
pnpm add nestia
Imports
- main
const main = require('nestia')import { main } from 'nestia' - IConfiguration
import { IConfiguration } from 'nestia'import type { IConfiguration } from 'nestia' - ECommand
import { ECommand } from 'nestia'
Quickstart
import { ECommand, main } from 'nestia';
import * as path from 'path';
import * as fs from 'fs/promises';
async function setupNestiaProject() {
const projectDir = path.join(process.cwd(), 'my-nestia-app');
await fs.mkdir(projectDir, { recursive: true });
process.chdir(projectDir);
console.log(`Initializing Nestia project in ${projectDir}...`);
await main({
command: ECommand.init,
input: ['--project', 'tsconfig.json'],
});
console.log('Nestia project initialized.');
console.log('Generating SDK and Swagger...');
await main({
command: ECommand.sdk,
input: ['--config', 'nestia.config.ts'],
});
console.log('SDK and Swagger generated successfully.');
console.log('Now you can explore your generated SDK and Swagger documentation!');
console.log(`Check out ${path.join(projectDir, 'src/api/index.ts')} for the SDK.`);
}
setupNestiaProject().catch(console.error);