-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (28 loc) · 1.04 KB
/
server.js
File metadata and controls
34 lines (28 loc) · 1.04 KB
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
33
34
const RabbitmqConnection = require('./messaging/rabbitmqConnection');
const db = require('./config/db');
const logger = require('./utils/logger');
const CurrencyUpdater = require('./jobs/currencyUpdater');
async function startServer() {
try {
// Wait for RabbitMQ connection before starting server
// 1. Create a new connection to RabbitMQ
await RabbitmqConnection.getConnection();
// 2. Connect to database
await db.connect();
const { createApp, initializeConsumers } = require('./app');
// 3. Initialize consumers
await initializeConsumers();
// 4. Create the Express app
const app = await createApp();
// 5. Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, async () => {
logger.info(`Server running on port ${PORT}`);
await CurrencyUpdater.initialize();
});
} catch (error) {
logger.error(`Error starting server: ${error.message}`);
process.exit(1);
}
}
startServer();