File size: 937 Bytes
56ddde0
 
bb4fd67
6413440
 
 
 
 
0055017
aa680e5
 
 
b9b40d5
6413440
bb815e1
aa680e5
 
 
 
 
 
 
 
 
 
 
94ccbc7
aa680e5
 
 
 
e69b6a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// startup like fastapi similar

import { Database } from '../database/database.js';
import {
  UsernameDB,
  PasswordDB
} from '../config.js';
import mongoose from 'mongoose';
const port = 7860

const startup = async () => {
    try {
        mongoose.connect(`mongodb+srv://${UsernameDB}:${PasswordDB}@cluster0.1asx6h1.mongodb.net/AkenoXJs?retryWrites=true&w=majority`);
        console.log("Mongoose connected successful.");
        const dbClient = new Database("AkenoXJs");
        console.log("Starting application...");
        await dbClient.connect();
        console.log("MongoDB connected successfully.");
    } catch (error) {
        console.error("Error during startup:", error.message);
        process.exit(1);
    }
};

const startServer = async (app) => {
    await startup();
    app.listen(port, "0.0.0.0", () => {
        console.log(`Server running on http://localhost:${port}`);
    });
};

export { startServer };