-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
49 lines (39 loc) · 1.15 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
44
45
46
47
48
49
const express = require("express");
let bodyParser = require("body-parser");
let cors = require("cors");
const logger = require("morgan");
const dotenv = require("dotenv");
let compression = require('compression');
const app = express();
dotenv.config();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(logger("combined"));
app.use(compression());
const mongoConnectOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
keepAlive: true,
useCreateIndex: true
};
const db = require("./models");
db.mongoose.connect(process.env.MONGO_URI, mongoConnectOptions)
.then(() => {
console.log("Successfully connect to MongoDB.");
})
.catch(err => {
console.error("Connection error", err);
process.exit();
});
// Routes
require('./routes/auth.routes')(app);
require('./routes/user.routes')(app);
require('./routes/video.routes')(app);
require('./routes/list.routes')(app);
require('./routes/utils.routes')(app);
// Listen
const PORT = process.env.PORT;
app.listen(PORT || 3000, function () {
console.log("Server is running on Port: " + (PORT || 3000));
});