-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pdt24 25 | Create a wrapper for environment variables #9
base: main
Are you sure you want to change the base?
Conversation
src/main.ts
Outdated
await app.listen(process.env.APP_PORT ?? 3000, () => { | ||
console.info('Listening to server....'); | ||
console.info(`Server listening at port http://localhost:${process.env.APP_PORT}`); | ||
const port = envVariables.APP_PORT ?? 3000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for default value if we're already defining it in envVariables
src/app.module.ts
Outdated
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { validate } from './config/env.config'; | ||
import { ConfigModule } from '@nestjs/config'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer import aliases "@/*"
rather than relative imports.
It will help a lot for code organization.
src/config/env.config.ts
Outdated
}) | ||
.required(); | ||
|
||
export const validate = (): object => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use return type z.infer<typeof validationSchema>
instead of object
src/config/env.config.ts
Outdated
@@ -0,0 +1,48 @@ | |||
import { z } from 'zod'; | |||
export const envVariables = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const envVariables = { | |
export const env = { |
src/scripts/orm.config.ts
Outdated
username: process.env.POSTGRES_USER, | ||
password: process.env.POSTGRES_PASSWORD, | ||
database: process.env.POSTGRES_DB, | ||
port: +(envVariables.POSTGRES_PORT ?? '5432'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we return z.infer<typeof validationSchema>
env.POSTGRES_PORT will not be falsey.
src/scripts/orm.config.ts
Outdated
database: envVariables.POSTGRES_DB, | ||
synchronize: false, // Should be false in production to use migrations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
database: envVariables.POSTGRES_DB, | |
synchronize: false, // Should be false in production to use migrations | |
database: envVariables.POSTGRES_DB, | |
synchronize: ${env.NODE_ENV === APP_ENVIRONVENT.PRODUCTION} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
env.NODE_ENV !== APP_ENVIRONVENT.PRODUCTION
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick. Apart from this LGTM 🏆
src/scripts/orm.config.ts
Outdated
username: env.POSTGRES_USER, | ||
password: env.POSTGRES_PASSWORD, | ||
database: env.POSTGRES_DB, | ||
synchronize: env.NODE_ENV === APP_ENVIRONVENT.PRODUCTION ? false : true, // Should be false in production to use migrations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synchronize: env.NODE_ENV === APP_ENVIRONVENT.PRODUCTION ? false : true, // Should be false in production to use migrations | |
synchronize: env.NODE_ENV === APP_ENVIRONVENT.DEVELOPMENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🏆
src/config/env.config.ts
Outdated
DEFAULT = 587, | ||
TLS = 465, | ||
} | ||
const validationSchema = z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validationSchema
-> appEnvSchema
.gitignore
Outdated
@@ -54,3 +54,5 @@ pids | |||
|
|||
# Diagnostic reports (https://nodejs.org/api/report.html) | |||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | |||
|
|||
ormconfig.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this file be ignored @pratham-outside
Quality Gate passedIssues Measures |
Tasks
Changes