NestJS
You should build your application as a tree of modules, controllers, and providers. The seed app exposes a single GET / endpoint that returns "Hello, World!" — extend it by adding more routes, services, and modules following the same pattern.
Entry file
The solution files are organized under src/:
src/main.ts— bootstraps the application and starts the HTTP server on port3000(preloaded, hidden, read-only).src/app.module.ts— the root module wiring controllers and providers (preloaded, read-only).src/app.controller.ts— the root controller exposingGET /(preloaded, read-only).src/app.service.ts— the service providing the response string (editable solution file).
Server configuration for API Tester
The server is started by src/main.ts (NestFactory.create(AppModule) listening on port 3000) so it is running when you use the API Tester tab. The API Tester sends real HTTP requests against your NestJS app and shows the response side-by-side.
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();Version
Running on Node.js v22.0.0 with NestJS 11.
Supported languages
TypeScript
Testing framework
Special reminders and implementation details
- Every provider needs the
@Injectable()decorator. Forgetting it leads to a confusingNest can't resolve dependencieserror at runtime. - Every controller and provider must be registered in a module's
controllers: [...]orproviders: [...]array. If you addFooServicebut forget to list it, NestJS won't see it. - Tests use @nestjs/testing to spin up a small
TestingModulewith just the providers a controller needs — no need to bootstrap the full app.
Example with @nestjs/testing:
import 'reflect-metadata';
import { describe, it, expect, beforeEach } from 'vitest';
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './src/app.controller';
import { AppService } from './src/app.service';
describe('AppController', () => {
let controller: AppController;
beforeEach(async () => {
const moduleRef: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService]
}).compile();
controller = moduleRef.get<AppController>(AppController);
});
it('returns "Hello, World!" on GET /', () => {
expect(controller.getHello()).toBe('Hello, World!');
});
});Included libraries
- @nestjs/common
- @nestjs/core
- @nestjs/platform-express
- @nestjs/testing
- reflect-metadata
- rxjs
- typescript
- vitest
How to debug
NestJS is a backend framework — your code runs in Node, not the browser. Three main ways to inspect runtime behavior:
1. Logs from controllers and services
Use console.log or the built-in Logger for structured output:
import { Controller, Get, Logger } from '@nestjs/common';
@Controller('items')
export class ItemsController {
private readonly logger = new Logger(ItemsController.name);
@Get()
list() {
this.logger.log('GET /items called');
return [];
}
}Output appears in the dev server terminal (or in the embedded Preview's debug panel).
2. API Tester
Use the API Tester tab in the right panel to send real HTTP requests (GET / POST / PUT / PATCH / DELETE) to your running NestJS server. Pick a method, type a path (e.g. /items), add headers/params/body, and hit Send. The response (status, headers, body, time) renders side-by-side so you can iterate on controllers and services without leaving the editor.
3. Steps to Debug Using Console Logs
Identify the Problem Area: Decide whether the issue is in the controller, a service, or a custom provider.
Insert
console.log()Statements: Add log calls before and after suspicious code. All NestJS logs go to the server terminal.Check the Results Output of your tests
Use Debug Icon in Preview Area: Click on the debug icon in the Preview area to check the terminal output.
Analyze the Output: Compare logs against the API Tester responses to spot wrong values, missing providers, or unhandled errors.
Common pitfalls
- Missing
@Injectable()on a provider → DI fails with a confusing "Nest can't resolve dependencies" error. Add the decorator to every service. - Forgot to register in
app.module.ts→ controller or provider is invisible to the runtime. Add it tocontrollers: [...]orproviders: [...]. - Test failures with
Nest can't resolve dependenciesinTest.createTestingModule(...)→ list every provider the controller needs, even transitively.