-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (40 loc) · 1.26 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
41
42
43
44
45
46
47
48
49
50
51
52
53
// GNU GENERAL PUBLIC LICENSE
// Version 3, 29 June 2007
// Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
// Everyone is permitted to copy and distribute verbatim copies
// of this license document, but changing it is not allowed.
// Preamble
// The GNU General Public License is a free, copyleft license for
// software and other kinds of works.
const express = require('express')
require('dotenv').config();
const cors = require('cors');
const bodyParser = require('body-parser');
const routes = require('./routes/routes');
const mongoConnect = require('./databaseAuth/mongoConnect');
// Create the express app
const app = express()
const port = process.env.PORT || 5000
mongoConnect();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// Routes and middleware
app.use('/api',routes);
// Error handlers
app.use(function fourOhFourHandler (req, res) {
res.status(404).send()
})
app.use(function fiveHundredHandler (err, req, res, next) {
console.error(err)
res.status(500).send()
})
// Start server
app.listen(port, function (err) {
if (err) {
return console.error(err)
}
console.log(`Server Started at :${port}`)
})