-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
29 lines (22 loc) · 818 Bytes
/
main.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
'use strict';
var chalk = require('chalk');
// Requires in ./db/index.js -- which returns a promise that represents
// mongoose establishing a connection to a MongoDB database.
var startDb = require('./db');
var seed = require('./seed');
// Create a node server instance! cOoL!
var server = require('http').createServer();
var createApplication = function () {
var app = require('./app.js');
server.on('request', app); // Attach the Express application.
};
var startServer = function () {
var PORT = process.env.VCAP_APP_PORT || 3000;
server.listen(PORT, function () {
console.log(chalk.blue('Server started on port', chalk.magenta(PORT)));
});
};
startDb.then(createApplication).then(startServer).catch(function (err) {
console.error(chalk.red(err.stack));
process.kill(1);
});