-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (35 loc) · 1.04 KB
/
server.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
var express = require('express'),
router = express.Router(),
bodyParser = require('body-parser'),
mongoose = require('mongoose'),
secrets = require('./server/config/secrets'),
app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
var port = process.env.PORT || 3000;
// Database
var connect = function () {
mongoose.connect(secrets.db, function (err) {
if (err) {
console.log('Error connecting to: ' + secrets.db + '. ' + err);
} else {
console.log('Succeeded connected to: ' + secrets.db);
}
});
};
connect();
mongoose.connection.on('error', console.log);
mongoose.connection.on('disconnected', connect);
// Models
require('./server/models/models');
// Routes
require('./server/config/routes')(app);
app.use('/', router);
app.listen(port, function (error) {
if (error) {
return console.log(error);
}
console.log("Express server listening on port " + port);
});
require('./server/config/errors')(app);
module.exports = app;