-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
45 lines (38 loc) · 1.15 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
44
45
// Make sure we are running node 7.6+
const [major, minor] = process.versions.node.split('.').map(parseFloat);
if (major < 7 || (major === 7 && minor <= 5)) {
console.log('🛑 Please go to nodejs.org and download version 7.6 or greater. 👌\n ');
process.exit();
}
/**
* Import environmental variables from our variables.env file
*/
require('dotenv').config({ path: '.env' });
/**
* Import data models
*/
require('./models/Listing');
/**
* Connect to MongoDB.
*/
const mongoose = require('mongoose');
mongoose.Promise = global.Promise; // Use ES6 Promise
const app = require('./app');
if (app.get('env') === 'development') {
mongoose.connect(process.env.DATABASE_DEV);
} else {
mongoose.connect(process.env.DATABASE_PROD);
}
mongoose.connection.on('error', (err) => {
console.error(err);
console.log('MongoDB connection error. Please make sure MongoDB is running.');
process.exit();
});
/**
* Start Mangrove Places!
*/
app.set('port', process.env.PORT || 8888);
const server = app.listen(app.get('port'), () => {
console.log('Mangrove Places is running at http://localhost:%d', app.get('port'));
console.log('Press CTRL-C to stop\n');
});