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