diff --git a/.env.template b/.env.template new file mode 100644 index 0000000000000000000000000000000000000000..8f55cbd31da03a3d6b8ce445d15f517556094b2a --- /dev/null +++ b/.env.template @@ -0,0 +1 @@ +PORT= \ No newline at end of file diff --git a/src/infrastructure/express-application.ts b/src/infrastructure/express-application.ts index d7996f0f15e6c7d8be5b8a72bec1056d561af0a4..625bd680a19f2988840ee6c41834e7250de6790b 100644 --- a/src/infrastructure/express-application.ts +++ b/src/infrastructure/express-application.ts @@ -1,9 +1,32 @@ import { ExpressServer } from './express-server'; +import * as dotenv from 'dotenv'; export class ExpressApplication { - private server = new ExpressServer('3000'); + private server: ExpressServer; + + constructor() { + this.configureEnvironment(); + + const port = this.getPort(); + this.server = new ExpressServer(port); + } bootstrap(): void { this.server.bootstrap(); } + + private configureEnvironment(): void { + dotenv.config({ + path: '.env', + }); + } + + private getPort(): string { + const port = process.env.PORT; + if (!port) { + throw new Error('No port was found in env file.'); + } + + return port; + } }