-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (35 loc) · 1.19 KB
/
server.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
41
42
43
// Import required modules
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
// Import configuration files
const serverConfig = require('./configs/server.config');
const dbConfig = require('./configs/db.config');
// Import models and routes
const User = require('./models/user.model');
const authRoutes = require('./routes/auth.routes');
const userRoutes = require('./routes/user.routes');
const ticketRoutes = require('./routes/ticket.routes');
// Create an instance of the express application
const app = express();
// Middleware to parse JSON bodies
app.use(bodyParser.json({}));
// Middleware to parse URL-encoded bodies
app.use(express.urlencoded({ extended: true }));
// Use the authentication routes
app.use(authRoutes);
app.use(userRoutes);
app.use(ticketRoutes);
// Connect to the database
mongoose.connect(dbConfig.DB_URL);
const db = mongoose.connection;
db.on('error', () => {
console.log('error while connecting to db');
});
db.once('open', () => {
console.log('connected to db');
});
// Start the server
app.listen(serverConfig.PORT, () => {
console.log(`Application started on port num : ${serverConfig.PORT}`);
});