-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 895 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 895 Bytes
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
const express = require('express');
const api = express();
api.use(express.json());
const settings = require('./data/settings.json');
//Initialize the mongoDB database
const persistence = require('mongoose');
async function Main(){
await persistence.connect(settings.PersistenceConnectionString);
}
//Connect to the mongoDB Database, then initialize the controllers
Main().catch(err => console.log(err)).then(() => {
console.log('Connected database!');
InitializeControllers();
});
//Read all controllers (.js files in /src/controllers) and initialize them
function InitializeControllers(){
var glob = require("glob");
glob("src/controllers/*.js", async function (er, files) {
files.forEach(function(fileName){
require("./" + fileName)(api, persistence);
console.log('Initialized ' + fileName);
});
});
}
api.listen(4921);