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

Switch to nest-typed-config for configuration #34

Open
Nikaple opened this issue Oct 11, 2021 · 0 comments
Open

Switch to nest-typed-config for configuration #34

Nikaple opened this issue Oct 11, 2021 · 0 comments

Comments

@Nikaple
Copy link

Nikaple commented Oct 11, 2021

Nest-typed-config is a module which enables defining config schema like request DTOs, and it supports reading configuration from environment variables, local files or remote configuration center.

In this boilerplate, three types of configurations are included: App, JWT and DB, which can be defined in a local toml file for better organization:

# .env.toml
[App]
env = 'dev'
url = 'http://localhost'

[JWT]
secretKey = 'uAsBw6WxqD'
expirationTime = 3600

[DB]
type = 'mariadb'
username = 'nest'
password = 'nest'
host = 'db'
port = 3306
database = 'nest'
sync = false

More importantly, nest-typed-config provides type-safe configurations, for example in app.module.ts:

TypeOrmModule.forRootAsync({
    // DBConfig is defined in config schema, and automatically injected
    useFactory: (dbConfig: DBConfig) => {
        return {
            ...dbConfig,
            entities: [__dirname + './../**/**.entity{.ts,.js}'],
            synchronize: dbConfig.sync,
        }; // No type casting is required
    },
})

Please let me know your thoughts, and I can open a pull request if this sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant