
Angular (frontend) and NestJS (backend) are a match made in developer heaven. Both leverage TypeScript, share similar modular architectures, and prioritize scalability—making them ideal for full-stack projects. In this guide, you’ll build a simple Task Manager app with:
npm install -g @angular/cli)npm install -g @nestjs/cli)Choose npm as your package manager.
nest new task-manager-api Create a tasks resource with CRUD endpoints:
nest generate resource tasks Select REST API and confirm creating CRUD entry points.
Update src/tasks/entities/task.entity.ts:
export class Task {
id: number;
title: string;
description?: string;
completed: boolean;
} In tasks.service.ts, add a temporary array:
private tasks: Task[] = []; Implement CRUD methods (e.g., create(), findAll(), update()).
Run npm run start:dev and visit http://localhost:3000/tasks. Use Postman to verify endpoints.
ng new task-manager-ui --routing --style=scss ng generate service services/task Inject HttpClient to connect to your NestJS API:
@Injectable({ providedIn: 'root' })
export class TaskService {
private apiUrl = 'http://localhost:3000/tasks';
constructor(private http: HttpClient) {}
getTasks(): Observable<Task[]> {
return this.http.get<Task[]>(this.apiUrl);
}
// Add create(), update(), delete() methods
} Generate a TaskListComponent:
ng generate component components/TaskList Fetch data in task-list.component.ts:
tasks$: Observable<Task[]>;
constructor(private taskService: TaskService) {
this.tasks$ = this.taskService.getTasks();
} Use Angular Reactive Forms to submit new tasks:
<form [formGroup]="taskForm" (ngSubmit)="onSubmit()">
<input formControlName="title" placeholder="Title">
<textarea formControlName="description"></textarea>
<button type="submit">Add Task</button>
</form> In main.ts, add:
app.enableCors(); npm run start:dev (NestJS on port 3000)ng serve (Angular on port 4200)Visit http://localhost:4200 to test the full-stack app!
Deploy your app using:
Dockerfiles for both projects.Task interfaces to sync frontend/backend.HttpErrorInterceptor.OnPush change detection.app.enableCors() and proxy configurations.