-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (35 loc) · 1.13 KB
/
app.js
File metadata and controls
49 lines (35 loc) · 1.13 KB
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
var express = require('express'),
mysql = require('mysql'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
app = express(),
config = require('./config.js'),
boot = require('./libs/boot.js')
;
/* Initialize connection to MySQL */
var connector = mysql.createConnection(config.mysql);
connector.connect(function(err) {
if (err) {
console.error('Error connecting MySQL: ' + err.stack);
return;
}
console.log(config.app.name + ' has been connected to MySQL successfully.');
});
/* Set up views directory and view engine. */
app.set('views', './views');
app.set('view engine', 'jade');
/* Set up static assets directory. */
app.use('/public', express.static(__dirname + '/public'));
/* Set up body parser for handling submitted data. */
app.use(bodyParser.urlencoded({
extended: true
}));
/* Set up logger. */
app.use(morgan(config.morgan.mode));
/* Load all controller. */
boot(app, connector, {verbose: true});
/* Start server! */
var server = app.listen(config.app.port, function () {
var port = server.address().port
console.log(config.app.name + ' server is listening at port ' + port + '.');
});