-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.js
43 lines (38 loc) · 1.34 KB
/
start.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
42
43
const mongoose = require("mongoose");
const Agenda = require("agenda");
const Agendash = require("agendash");
// Make sure node 7.6+
const [major, minor] = process.versions.node.split(".").map(parseFloat);
if (major <= 7 && minor <= 5) {
console.log(
"You are on an older version of node. Please go to nodejs.org and download version 7.6 or greater."
);
process.exit();
}
// import environmental variables from variables.env file
require("dotenv").config({ path: "variables.env" });
// Connect to Database and handle bad connections
const databaseUrl =
process.env.NODE_ENV === "development"
? process.env.DATABASE_DEV
: process.env.DATABASE;
mongoose.connect(databaseUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
mongoose.Promise = global.Promise; // Tell Mongoose to use ES6 promises
mongoose.connection.on("error", (err) => {
console.error(`🙅 🚫 🙅 🚫 🙅 🚫 🙅 🚫 → ${err.message}`);
});
//import all models
require("./models/User");
require("./models/Result");
require("./models/Project");
require("./models/Job");
require("./models/Receipt");
// Start the app
const app = require("./app");
app.set("port", process.env.PORT || 8080);
const server = app.listen(app.get("port"), () => {
console.log(`Express running → PORT ${server.address().port}`);
});