Getting Started
Install
Section titled “Install”bun add nestjs-platform-elysia @nestjs/common @nestjs/core elysiaFor CORS:
bun add @elysiajs/corsFor WebSocket gateways:
bun add @nestjs/websocketsBootstrap
Section titled “Bootstrap”import { NestFactory } from '@nestjs/core';import { ElysiaAdapter, type NestElysiaApplication } from 'nestjs-platform-elysia';import { AppModule } from './app.module';
async function bootstrap() { const app = await NestFactory.create<NestElysiaApplication>( AppModule, new ElysiaAdapter(), );
app.enableCors();
await app.listen(3000);}
bootstrap();That’s it. Write controllers and providers exactly as you would in a normal NestJS app — guards, pipes, interceptors, exception filters all flow through the same pipeline.
A minimal controller
Section titled “A minimal controller”import { Body, Controller, Get, Param, ParseIntPipe, Post } from '@nestjs/common';
@Controller('cats')export class CatsController { @Get() list() { return [{ id: 1, name: 'Mia' }]; }
@Get(':id') one(@Param('id', ParseIntPipe) id: number) { return { id, name: 'Mia' }; }
@Post() create(@Body() body: { name: string }) { return { id: 2, name: body.name }; }}What you get for free
Section titled “What you get for free”- Full Nest DI, modules, guards, pipes, interceptors, exception filters
- HTTP method coverage including WebDAV verbs (
PROPFIND,PROPPATCH,MKCOL, etc.) - URI / Header / Media-Type / Custom versioning via
app.enableVersioning(...) - CORS via
app.enableCors()(lazy-loads@elysiajs/cors) MiddlewareConsumer.apply().forRoutes()Express-style middlewareapp.inject(new Request(...))for testing without binding a portapp.register(plugin)to mount Elysia plugins (e.g.swagger(),bearer())app.mount(path, fetchHandler)to mount sub-apps
Continue with Route Decorators to see how to attach Elysia schemas and lifecycle hooks to your controller methods.