Skip to content

Migrating from NestJS

Shokupan supports NestJS-style decorators for defining controllers and handling requests, but without the heavy module boilerplate.

Shokupan controllers are plain classes with decorators.

NestJS:

@Controller('users')
export class UserController {
@Get(':id')
getUser(@Param('id') id: string) {
return { id };
}
}

Shokupan:

import { Controller, Get, Param, Shokupan } from 'shokupan';
@Controller('/users')
export class UserController {
@Get('/:id')
getUser(@Param('id') id: string) {
return { id };
}
}
const app = new Shokupan();
// Register the controller (/api/users)
app.mount('/api', new UserController());
app.listen(3000);

Shokupan has a built-in lightweight DI container. You can use @Inject or @Injectable.

import { Injectable, Inject, Controller, Get } from 'shokupan';
// 1. Define a Service
@Injectable('singleton')
class UserService {
getUsers() {
return ['Alice', 'Bob'];
}
}
// 2. Inject into Controller
@Controller('/users')
class UserController {
// Property Injection
@Inject(UserService)
private userService: UserService;
@Get('/')
list() {
return this.userService.getUsers();
}
}

[!NOTE] Unlike NestJS, you don’t need to declare “Modules” or “Providers” arrays. Services are simpler and resolved globally or per-scope. This is an intentional architectural decision in order to follow KISS principles.