Skip to content

Commit 3cc6347

Browse files
committed
chore: updated file .env and validation
1 parent 4438a53 commit 3cc6347

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NODE_ENV=
1+
NODE_ENV="production"
22

33
SERVER_PORT=
44

.env.example-test-e2e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NODE_ENV=
1+
NODE_ENV="production"
22

33
SERVER_PORT=
44

src/helpers/validation-schema-env.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,27 @@ const schema = {
2222

2323
const validate = ajv.compile(schema);
2424

25+
interface EnvVariables {
26+
TYPEORM_HOST: string;
27+
TYPEORM_PORT: string;
28+
TYPEORM_USERNAME: string;
29+
TYPEORM_PASSWORD: string;
30+
TYPEORM_DATABASE: string;
31+
}
32+
2533
export const validateSchemaEnv = (env: unknown) => {
2634
const valid = validate(env);
2735
if (!valid) {
2836
const errorMessages = validate.errors
29-
.map((err) => ` Property${err.instancePath} ${err.message}`)
30-
.join(', ');
37+
?.map(
38+
(err: { instancePath?: string; message?: string }) =>
39+
`- ${err.instancePath || ''} ${err.message || 'Unknown error'}`,
40+
)
41+
.join('\n') ?? 'Unknown error';
3142
console.error(
32-
`Environment validation error:${errorMessages}`,
43+
`Environment validation error: \n${errorMessages}`,
3344
'EnvValidation',
3445
);
3546
}
36-
return env;
47+
return env as EnvVariables;
3748
};

0 commit comments

Comments
 (0)