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
| export const database = { | |
| type: 'postgres', | |
| host: process.env.DB_HOST, | |
| port: Number(process.env.DB_PORT || 5432), | |
| username: process.env.DB_USERNAME, | |
| password: process.env.DB_PASSWORD, | |
| database: process.env.DB_DATABASE, | |
| name: 'default', | |
| }; |
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
| // 1. Import the full config object | |
| import { Config } from '@config'; | |
| console.log(Config.database); | |
| // 2. Import a single "feature" | |
| import { database } from '@config'; | |
| // 3. Import the full config but as a namespace | |
| import * as config from '@config'; |
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
Show hidden characters
| { | |
| "compilerOptions": { | |
| "paths": { | |
| "@config": ["src/config"] | |
| } | |
| } | |
| } |
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 path from 'path'; | |
| /** | |
| * I use app-root-path to determine where the root of the project is. By doing this, I am able | |
| * to place this index.ts file anywhere in the project structure. | |
| */ | |
| import * as appRootPath from 'app-root-path'; | |
| /** | |
| * This is an awesome way to read in .env files if you don't always want to load the env in |
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
| export default () => ({ | |
| port: parseInt(process.env.PORT, 10) || 3000, | |
| database: { | |
| host: process.env.DATABASE_HOST, | |
| port: parseInt(process.env.DATABASE_PORT, 10) || 5432 | |
| } | |
| }); |
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
| interface DatabaseConfig { | |
| host: string; | |
| port: number; | |
| } | |
| const dbConfig = this.configService.get<DatabaseConfig>('database'); | |
| // you can now use `dbConfig.port` and `dbConfig.host` | |
| const port = dbConfig.port; |
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
| FROM node:lts | |
| COPY package.json package.json | |
| COPY package-lock.json package-lock.json | |
| RUN npm install | |
| COPY entrypoint.sh /entrypoint.sh | |
| COPY . . |
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
| version: '3.6' | |
| services: | |
| database: | |
| image: postgres | |
| environment: | |
| - POSTGRES_PASSWORD=testing | |
| - POSTGRES_USER=testing | |
| - POSTGRES_DB=testing | |
| ports: | |
| - 5432 |
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
| #!/bin/bash | |
| echo "Running database migrations!" | |
| # First we run the migration of the database | |
| npm run migrate | |
| # Now start the service so that the port opens and the wait command can continue | |
| npm run start |
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
| version: '3.6' | |
| services: | |
| database: | |
| image: postgres | |
| environment: | |
| - POSTGRES_PASSWORD=testing | |
| - POSTGRES_USER=testing | |
| - POSTGRES_DB=testing | |
| ports: | |
| - 5432 |