move database configs to .env

This commit is contained in:
João Geonizeli
2022-07-10 15:39:51 -03:00
parent af0bc0a082
commit c3793ee661
4 changed files with 26 additions and 16 deletions

View File

@@ -2,4 +2,7 @@ ENV=development
PORT=5000
SECRET=aE8efkEP8+V/ibEQl8IKbw==
DB_NAME=todoListDev
DB_HOST=localhost
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=todoListDev

View File

@@ -2,4 +2,7 @@ ENV=test
PORT=5000
SECRET=aE8efkEP8+V/ibEQl8IKbw==
DB_NAME=todoListTest
DB_HOST=localhost
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=todoListTest

3
server/src/env.d.ts vendored
View File

@@ -1,5 +1,8 @@
declare namespace NodeJS {
interface ProcessEnv {
DB_HOST?: string;
DB_USER?: string;
DB_PASSWORD?: string;
DB_NAME?: string;
NODE_ENV?: 'test' | 'development' | 'production';
}

View File

@@ -1,21 +1,22 @@
import * as dotenv from 'dotenv';
import * as dotenv from "dotenv";
import "reflect-metadata";
import { DataSource } from "typeorm";
import { Project } from "../entity/project.entity";
import { Task } from '../entity/task.entity';
import { Task } from "../entity/task.entity";
import { User } from "../entity/user.entity";
dotenv.config();
dotenv.config({
path: process.env.NODE_ENV === "test" ? ".env.test" : ".env",
});
export const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "joao",
database: process.env.DB_NAME,
synchronize: true,
logging: false,
entities: [User, Project, Task],
migrations: [],
subscribers: [],
})
type: "postgres",
host: process.env.DB_HOST,
port: 5432,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
synchronize: true,
logging: false,
entities: [User, Project, Task],
});