From 7dcc6a58d70889b6d88cb81493ba32f2a5485e0e Mon Sep 17 00:00:00 2001 From: Mathias Wagner <germannewsmaker@gmail.com> Date: Tue, 6 Sep 2022 19:59:20 +0200 Subject: [PATCH] Integrated the database into the app.ts & added the start method --- app.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app.ts b/app.ts index a439257..aeb7330 100644 --- a/app.ts +++ b/app.ts @@ -1,3 +1,18 @@ +import mongoose, {CallbackError} from 'mongoose'; +import * as api from './server/api'; + // Load & check environment require('dotenv').config(); -require('./util/envCheck').validate(); \ No newline at end of file +require('./util/envCheck').validate(); + +// Connect to database +mongoose.connect(process.env.MONGOOSE_STRING || '', (e: CallbackError) => { + if (e) throw new Error(`Could not connect to database: ${e.message}`); + console.log("[DB] Successfully connected to the database"); + start(); +}); + +// Start all servers +const start = () => { + api.startServer(parseInt(process.env.API_PORT || '')); +} \ No newline at end of file