Skip to content

Commit 5d18cbf

Browse files
committed
improves docs
1 parent de01337 commit 5d18cbf

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

README.md

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,77 @@
11
## Description
22

3-
Winston and Nest-Winston opionated configuration for NestJS. This package depends on @gedai/core and @nestjs/config, be sure to install and setup those for everything to work as expected.
3+
Opionated common configuration for NestJS services. This package depends on @gedai/core and @nestjs/config. Be sure to install and setup those for everything to work as expected.
44

5-
This package uses the following environment variables during its setup:
5+
## Configuration:
6+
7+
This package uses a few environment variables for configuration. The folowing lists the available values for each configuration variable.
68

79
```
810
NODE_ENV="{development,testing,staging,production}"
9-
APP_NAME="myApp"
11+
SERVICE_NAME="myApp"
1012
LOG_LEVEL="{debug,info,warn,error}"
13+
LOG_FORMAT="{pretty,json}"
14+
INSPECT_HTTP_TRAFFIC="{all,none,inbound,outbound}"
1115
```
1216

1317
- development and testing will output colorized format
1418
- staging and production will output json format
1519

16-
## Installation
20+
## Getting Started
21+
22+
### Step 1: Installation
1723

1824
```bash
19-
$ npm install @gedai/core @gedai/logger @nestjs/config
25+
$ npm install @gedai/core @gedai/common @nestjs/config
2026
```
2127

22-
## Running the app
28+
### Step 2: The Setup
2329

24-
### Step 1:
30+
Import the required modules
31+
32+
```typescript
33+
// app.module.ts
34+
import { ContextModule } from '@gedai/core';
35+
import { Module } from '@nestjs/common';
36+
import { ConfigModule } from '@nestjs/config';
37+
import { randomUUID } from 'crypto';
38+
import { AppController } from './app.controller';
39+
import { AppService } from './app.service';
40+
41+
@Module({
42+
imports: [
43+
// <<-- Setup Config Module Here -->>
44+
ConfigModule.forRoot({ isGlobal: true }),
45+
// <<-- Setup Context Module Here -->>
46+
ContextModule.forRoot({}),
47+
],
48+
controllers: [AppController],
49+
providers: [AppService],
50+
})
51+
export class AppModule {}
52+
```
2553

2654
Apply global wide configuration in main.ts
2755

2856
```typescript
2957
// app.module.ts
30-
import { configureLogger } from '@gedai/logger';
58+
import { configureContextWrappers } from '@gedai/core';
59+
import { configureLogger } from '@gedai/common';
3160
import { NestFactory } from '@nestjs/core';
3261
import { AppModule } from './app.module';
3362

3463
async function bootstrap() {
35-
const app = await NestFactory.create(AppModule);
36-
configureLogger(app);
64+
const app = await NestFactory.create(AppModule)
65+
// <<-- Setup Context Wrappers Here -->>
66+
.then(configureContextWrappers())
67+
// <<-- Setup Logger Here -->>
68+
.then(configureLogger());
3769
await app.listen(3000);
3870
}
3971
bootstrap();
4072
```
4173

42-
## Step 2:
74+
### Step 3: Do Magic!
4375

4476
You can now use the Nest's default logger with preconfigured setup.
4577

@@ -50,22 +82,32 @@ import { Injectable } from '@nestjs/common';
5082

5183
@Injectable()
5284
export class AppService {
85+
// <<-- Create a scoped instance of nest's Logger -->>
5386
private logger = new Logger(this.constructor.name);
5487

5588
constructor(private readonly context: ContextService) {}
5689

5790
getHello(): string {
58-
const message = 'Hello, World!';
59-
this.logger.log(message);
60-
// outputs: [nest-app] Info 3/16/2024, 3:16:59 PM [AppService] Hello, World! - {"traceId":"20889865-510c-433c-ac0a-a04f27b89d35"}
61-
/* Optionally:
62-
* this.logger.log({ message, ...additionalDataForLogs });
63-
*/
91+
// <<-- Whenever you use the logger, it will be tracked with the contextId-->>
92+
this.logger.log('Hello, Jack!');
6493
return message;
6594
}
6695
}
6796
```
6897

98+
## Features
99+
100+
- Logging
101+
- Anonymized keys on logged objects
102+
- Inbound HTTP traffic inspection
103+
- Outbound HTTP traffic inspection
104+
- Compression
105+
- Helmet
106+
- Validation
107+
- CORS
108+
- API Versioning
109+
- Route Prefixing
110+
69111
## License
70112

71113
Gedai is [MIT licensed](LICENSE).

0 commit comments

Comments
 (0)