-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (44 loc) · 1.54 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* awk application initialization
*
* @author Jingming Niu
* @since 2015-03-23
*/
(function() {
/** db initialization */
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI);
console.log("init: successfully connected to mongodb");
var questionSchema = new mongoose.Schema({
data: String,
updated_at: { type: Date, default: Date.now }
});
console.log("init: successfully created schema");
var Question = mongoose.model('t_questions', questionSchema);
/** dustjs initialization */
var dust = require('dustjs-linkedin');
dust.helpers = require('dustjs-helpers');
console.log("init: successfully loaded dust");
/** App initialization */
var express = require('express');
var consolidate = require('consolidate');
var app = express();
console.log("init: successfully created express instance");
app.engine('dust', consolidate.dust);
app.set('view engine', 'dust');
app.set('views', __dirname + '/dust');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname));
console.log("init: successfully set initialization requirements");
app.get('/', function (request, response) {
console.log("Handling request: " + request);
Question.findOne({}, function(error, question) {
console.log(question);
response.render('index', { question: question.data });
});
});
console.log("init: loading application");
app.listen(app.get('port'), function () {
console.log("Node app is running at localhost:" + app.get('port'));
});
}());