Updated Quickstart (markdown)
parent
17f069e84b
commit
8b492447d1
@ -1 +1,65 @@
|
||||
TODO
|
||||
# Getting Started
|
||||
|
||||
Let's start from making a normal NestJS app.
|
||||
|
||||
```ts
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Important:** This decorator package is only accepting asynchronous function for now.
|
||||
|
||||
So we should change things to use async.
|
||||
|
||||
```ts
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
async getHello(): Promise<string> {
|
||||
return await this.appService.getHello();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This is the template you will get when you start with `nest new [name]`.
|
||||
|
||||
Now install `nestlogged` package.
|
||||
|
||||
```sh
|
||||
npm install nestlogged
|
||||
```
|
||||
|
||||
Or,
|
||||
|
||||
```sh
|
||||
yarn add nestlogged
|
||||
```
|
||||
|
||||
# Add Logging
|
||||
|
||||
In this package, logging decorator is separated by two kind.
|
||||
|
||||
1. LoggedRoute is used for methods in Controllers, with method decorators like @Get, @Post, etc.
|
||||
|
||||
2. LoggedFunction is used for methods in any other class methods, like service.
|
||||
|
||||
So, we can add a LoggedRoute decorator in controller example above.
|
||||
|
||||
```ts
|
||||
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user