-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.39 KB
/
index.js
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
35
36
37
38
39
40
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const authenticationRoutes = require('./src/routes/authRoutes');
const marketDataRoutes = require('./src/routes/marketDataRoutes');
const notificationRoutes = require('./src/routes/notificationRoutes');
const portfolioRoutes = require('./src/routes/portfolioRoutes');
const userManagementRoutes = require('./src/routes/userManagementRoutes');
const errorMiddleware = require('./src/middlewares/errorMiddleware');
const app = express();
// Load environment variables from .env file
dotenv.config();
// Connect to MongoDB database
mongoose.connect(process.env.DB_CONNECT, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
console.log('Connected to MongoDB database');
}).catch((error) => {
console.log(`Failed to connect to MongoDB database: ${error}`);
});
// Set up JSON body parsing middleware
app.use(bodyParser.json());
// Set up API endpoints
app.use('/auth', authenticationRoutes);
app.use('/market', marketDataRoutes);
app.use('/notifications', notificationRoutes);
app.use('/portfolio', portfolioRoutes);
app.use('/users', userManagementRoutes);
// Set up error middleware
app.use(errorMiddleware);
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}...`);
});