Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: server-env 리드미, jsdoc 작성 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/server/env/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
# env

Get process.env props

## Installation

```bash
$ npm i @awesome-dev/server-env
```

## Usage

```bash
export interface CustomConfigOption {
userId: string;
userPassword: string;
jwtSecretKey: string;
}

@Injectable()
export class CustomConfig {
public constructor(private readonly option: CustomConfigOption) {}

getOption(key: keyof CustomConfigOption) {
return this.option[key];
}
}
```

```bash
@Module({})
export class CustomModule {
static forRoot(): DynamicModule {
const config = loadEnv([
'USER_ID',
'USER_PASSWORD',
'JWT_SECRET_KEY',
] as const);

const ConfigProvider: Provider = {
provide: CustomConfig,
useFactory: () =>
new CustomConfig({
userId: config.USER_ID,
userPassword: config.USER_PASSWORD,
jwtSecretKey: config.JWT_SECRET_KEY,
}),
};

return {
module: CustomModule,
controllers: [],
providers: [ConfigProvider],
exports: [ConfigProvider],
};
}
}
```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## License

Nest is [MIT licensed](LICENSE).
3 changes: 3 additions & 0 deletions packages/server/env/src/loadEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { config } from 'dotenv';

config();

/**
* process.env 파일의 props를 가져옵니다.
*/
export function loadEnv<K extends string>(propNames: readonly K[], strict = true) {
const env: Record<string, unknown> = {};

Expand Down