Migrated the server.ts file

This commit is contained in:
Mathias Wagner 2023-04-06 18:11:31 +02:00
parent d66be23a7d
commit 316ddabc22
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -25,8 +25,9 @@ const run = () =>
app.listen(port, () => console.log(`LicenseAPI ${isDevelopment ? "development" : "production"} server started under port ${port}`));
// Connect to database
mongoose.connect(MONGOOSE_STRING, (error: CallbackError) => {
if (error) throw new Error(`Could not connect to database: ${error.message}`);
mongoose.connect(MONGOOSE_STRING).then(() => {
console.log(`Successfully connected to the database @${MONGOOSE_STRING.split("://")[1].split("/")[0]}`);
run();
}).catch((error: CallbackError) => {
if (error) throw new Error(`Could not connect to database: ${error.message}`);
});