Integrated the database into the app.ts & added the start method

This commit is contained in:
Mathias Wagner 2022-09-06 19:59:20 +02:00
parent 1aa963bdc9
commit 7dcc6a58d7
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

17
app.ts
View File

@ -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();
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 || ''));
}