-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (39 loc) · 1.23 KB
/
app.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
44
45
46
47
48
49
50
51
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
require('dotenv').config();
const mongoose = require('mongoose');
const app = express();
const authRoutes = require('./api/routes/auth');
const employeeRoutes = require('./api/routes/employee');
const leaveRoutes = require('./api/routes/leave');
const analyticsRoutes = require('./api/routes/analytics');
//db connection
mongoose
.connect(`mongodb+srv://super-admin:${process.env.PASSWORD}@cluster0.hzbov.mongodb.net/${process.env.DBNAME}?retryWrites=true&w=majority`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
})
.then(() => {
console.log("DB CONNECTED");
})
.catch((err) => {
console.log('ERROR: ', err);
});
//middlewares
app.use(bodyParser.json());
app.use(cors());
app.use(cookieParser());
//routes
app.use("/api/auth", authRoutes);
app.use("/api/employees", employeeRoutes);
app.use("/api/leaves", leaveRoutes);
app.use("/api/analytics", analyticsRoutes);
//port
const port = process.env.PORT || 5000;
//starting a server
app.listen(port, () => {
console.log("Listening at: ", port);
});