-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (59 loc) · 1.89 KB
/
index.js
File metadata and controls
71 lines (59 loc) · 1.89 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// env vars
const { PORT, MONGO_CONN, NODE_ENV } = require('./config');
// I like pretty things
const chalk = require('chalk');
// importing and init logger
// const logger = require('./server/utils/log.js');
// logger.error("lol it errors")
// logger.verbose("hello verboses")
// logger.warn("warning")
// logger.info("informational")
// Mongoose imports
const mongoose = require('mongoose');
mongoose.set('debug', NODE_ENV === "dev");
mongoose.Promise = global.Promise;
// Mongoose connection
mongoose.connect(MONGO_CONN);
mongoose.connection
.on('connected', () => {
console.log(chalk.bold.green("Connected to MongoDB")); /* eslint-disable-line babel/quotes */ // stings "" keys ''
})
.on('disconnected', () => {
console.log(chalk.bold.bgRed.white("***DB DISCONNECTED***")); /* eslint-disable-line babel/quotes */ // stings "" keys ''
// throw new Error("***DB DISCONNECTED***");
})
.on('error', (err) => {
console.log(chalk.bold.bgRed.white("***DB CONNECTION ERROR***")); /* eslint-disable-line babel/quotes */ // stings "" keys ''
throw err;
});
// importing models
require('./server/models/User.js');
require('./server/models/Room.js');
// Importing server
const httpServer = require('./server/app.js');
httpServer.listen(PORT);
httpServer
.on('listening', () => {
if (NODE_ENV !== "test") {
console.log(chalk.grey.bold('\n...'));
console.log(chalk.blue(`Starting Chat app...`));
console.log(chalk.magenta.bold(`Started!!!`));
console.log(chalk.grey.bold('...\n'));
}
})
.on('error', err => {
console.log(chalk.bold.bgRed.white("***ERROR***")); /* eslint-disable-line babel/quotes */ // stings "" keys ''
throw err;
});
// close function
function stop () {
httpServer.close();
mongoose.connection.close();
return true;
}
process.on('SIGINT', () => {
console.log("== Terminating App ==");
if (stop()) process.exit();
});
module.exports = httpServer;
module.exports.stop = stop;