learn nestjs code example

Example 1: nestjs code example

import { Controller, Get } from '@nestjs/common';

@Controller('/api')
export class AppController {

  @Get('/testAuth0')
  getHello() {
    return {
      status: 'ok'
    };
  }

  @Get('/health')
  getHealthCheck() {
    return {
      status: 'ok'
    };
  }
}

Example 2: nestjs tutorial for beginners

getCourses(): Promise<any> {
        return new Promise(resolve => {
            resolve(this.courses);
        });
    }

    getCourse(courseId): Promise<any> {
        let id = Number(courseId);
        return new Promise(resolve => {
            const course = this.courses.find(course => course.id === id);
            if (!course) {
                throw new HttpException('Course does not exist', 404)
            }
            resolve(course);
        });
    }

Example 3: nestjs tutorial for beginners

import { Injectable, HttpException } from '@nestjs/common';
import { COURSES } from './courses.mock';

@Injectable()
export class CoursesService {
    courses = COURSES;
}