-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 1.01 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
"use strict";
require("dotenv").config();
const env = "" + process.env.NODE_ENV;
const express = require("express");
const app = express();
const bodyConfig = {
limit: "10mb",
extended: true
};
app.use(express.urlencoded(bodyConfig));
app.use(express.json(bodyConfig));
const middleware = require("./config/middleware");
app.use(middleware.cors);
app.use(express.static('public'));
const config = require("./config/config")[env || "development"];
const mongoose = require("mongoose");
console.log("Trying to connect to database...");
mongoose.connect(config.database, config.mongoConfig, err => {
if (err) {
console.log("Could not connect to database.");
console.log(err);
} else {
console.log(`Connected to ${process.env.DB_NAME}.`);
}
});
const routes = require("./src/routes");
app.use("", routes);
const PORT = process.env.PORT || 8081;
app.listen(PORT);
console.log("Application listening on PORT: " + PORT);
console.log("http://localhost:" + PORT);
module.exports = app;