-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 822 Bytes
/
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
const express = require("express");
const logger = require("morgan");
const bodyParser = require("body-parser");
const app = express();
const mongo = require("./db/connect");
app.use( logger("dev") );
app.use( bodyParser.json() );
app.use( bodyParser.urlencoded({ extended: false }) );
require("./routes/views")(app);
require("./routes/api")(app);
require("./routes/special")(app);
async function initMongo(){
const db = await mongo.connect();
if(db) { initExpress(); }
}
function initExpress() {
console.log('Iniciando Express');
app.listen(3000, ()=>{
console.log("Express ha iniciado correctamente!");
process.on("SIGINT", closeApp);
process.on("SIGTERM", closeApp);
});
}
function closeApp(){
mongo.disconnect()
.then(()=>process.exit(0));
}
initMongo();