Skip to content

Instantly share code, notes, and snippets.

@Vatsalya-singhi
Created March 27, 2025 18:28
Show Gist options
  • Save Vatsalya-singhi/678a46a36ce3203b3c638930ba0a1376 to your computer and use it in GitHub Desktop.
Save Vatsalya-singhi/678a46a36ce3203b3c638930ba0a1376 to your computer and use it in GitHub Desktop.
// Users Service (Provides Business Logic)
import { Injectable } from '@nestjs/common';
// injectables include wide range of configurations such as when and how to initialise the provider
@Injectable()
export class UsersService {
private users = ['Alice', 'Bob', 'Charlie'];
findAll(): string[] {
return this.users;
}
}
// Users Controller (Depends on UsersService)
import { Controller, Get } from '@nestjs/common';
import { UsersService } from './users.service';
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {} // Dependency Injection
@Get()
findAll(): string[] {
return this.usersService.findAll(); // Uses service to get data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment