A wired-up NestJS feature module
A NestJS feature is three files that fit together: a service marked @Injectable, a controller that injects it and exposes routes, and a module that registers both. Writing the decorators, the constructor injection, and the CRUD handlers by hand is repetitive. This builder generates all three, correctly wired, from one resource name.
How it works
The tool derives class and path names from your resource (e.g. user → UsersController, UsersService, base path users). It emits three fenced blocks. The service is an @Injectable() class with findAll, findOne, create, update, and remove methods over an in-memory array as a placeholder. The controller is decorated @Controller('users'), injects the service via constructor(private readonly service: UsersService) {}, and maps @Get(), @Get(':id'), @Post(), @Patch(':id'), and @Delete(':id') to the service methods. The module is an @Module({ controllers: [...], providers: [...], exports: [...] }) that ties them together so it can be imported elsewhere.
Tips and example
- Replace the in-memory array in the service with a repository (Prisma/TypeORM) injected the same way.
- Add DTO classes plus a
ValidationPipeso@Body()payloads are validated. - Export the service from the module if another module needs to inject it.
import { Module } from "@nestjs/common";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";
@Module({
controllers: [UsersController],
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}