Created
April 4, 2025 02:12
-
-
Save rodrigobertin/978694280b72f4b0f9a6078cac4b219b to your computer and use it in GitHub Desktop.
Data source create Type ORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as dotenv from 'dotenv'; | |
import { DataSource, DataSourceOptions } from 'typeorm'; | |
dotenv.config(); | |
const isDevelopment = process.env.NODE_ENV !== 'production'; | |
console.log('isDevelopment', isDevelopment); | |
export const dataSourceOptions: DataSourceOptions = { | |
type: 'postgres', | |
host: process.env.POSTGRES_HOST || 'localhost', | |
port: parseInt(process.env.POSTGRES_PORT || '5432'), | |
username: process.env.POSTGRES_USER || '<user>', | |
password: process.env.POSTGRES_PASSWORD || '<password>', | |
database: process.env.POSTGRES_DB || '<database>', | |
entities: [__dirname + '/../**/*.entity{.ts,.js}'], | |
migrations: [__dirname + '/../../migrations/**/*{.ts,.js}'], | |
synchronize: false, | |
subscribers: [__dirname + '/../**/*.subscriber{.ts,.js}'], | |
}; | |
const dataSource = new DataSource(dataSourceOptions); | |
export default dataSource; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment