-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (33 loc) · 1.06 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
//required modules
let fs = require("fs");
let express = require("express");
let app = express();
let mongoose = require("mongoose");
let bodyParser = require("body-parser");
let configuration;
//bodyparser stuff
app.use(bodyParser.json());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/", express.static(__dirname + "/public"));
require("./routes")(app);
exports = app;
//constants
const PORT = process.env.PORT || 8080;
const settings = "settings.json";
const ERROR_TEXT =
"You must have a database string in the settings.json file or this app will not work!";
if (fs.existsSync(settings)) {
//read config. values from settings.json configuration file
configuration = JSON.parse(fs.readFileSync(settings));
if (!configuration.mongoUrl) {
throw new Error(ERROR_TEXT);
}
} else {
throw new Error(ERROR_TEXT);
}
mongoose.Promise = global.Promise;
mongoose.connect(configuration.mongoUrl, { useMongoClient: true });
app.listen(PORT, function() {
console.log(`listening on ${PORT}`);
});