-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (31 loc) · 899 Bytes
/
app.js
File metadata and controls
38 lines (31 loc) · 899 Bytes
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
/**
* Application entrypoint that defines
* initialization logic.
* Requires the port to be used specified
* as the first argument in the command line.
* @module app
*/
var express = require('express');
var mongoose = require('mongoose');
var config = require('./config');
// Attempt database connection
var db = mongoose.connection;
// If no connection can be made, abort
db.on('error', function() {
console.error('Failed database connection attempt at ', config.db_address);
process.exit(1);
});
var app = express();
// Configure template engine
app.set('view engine', 'jade');
// Set routes
app.get('/', function(req, res) {
res.render('index');
});
db.once('open', function(callback) {
var server = app.listen(config.port, function() {
var host = server.address().address;
console.log('Listening on http://%s:%d', host, config.port);
});
});
module.exports = app;