-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1.15 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
const express = require('express')
const mongoose = require('mongoose')
const logger = require('./middleware/logger')
const jsonAPiRoutes = require('./apiRoutes.json')
require('dotenv').config();
const app = express();
// Init Middlewares
// Body Parser
app.use(express.json());
app.use(express.urlencoded({extended: false}));
// Middleware to log requests
app.use(logger);
// Home Route
app.get('/', (req, res) => res.json(jsonAPiRoutes));
// API Routes
app.use('/api/employees', require('./routes/api.employee'))
app.use('/api/logs', require('./routes/api.logs'))
// ENV
const dbConn = `mongodb+srv://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASS}@${process.env.MONGO_DB_CLUSTER}.hvghisd.mongodb.net/${process.env.MONGO_DB_DB}`
const PORT = process.env.PORT || 5000;
// Creating Connection
mongoose.connect(dbConn, {
useNewUrlParser: true,
useUnifiedTopology: true
})
// Check Connections
mongoose.connection.on('error', err => console.log("Databse Connection Error"))
mongoose.connection.on('connected', (err,res) => console.log("Database Connected"))
// Making Servers
app.listen(PORT, () => console.log(`Server is running at port: ${PORT}`))