-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (49 loc) · 1.55 KB
/
app.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
61
62
63
64
65
66
/*var moment = require('moment');
console.log(moment().format("ddd, hA"));
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
if (req.url === '/') {
fs.createReadStream(__dirname + '/index.htm').pipe(res);
else if (req.url === '/api') {
}
res.writeHead(200, { 'Content-Type': 'application/json' });
var obj = {
firstname: 'John',
lastname: 'Doe'
};
res.end(JSON.stringify(obj));
}
else {
res.writeHead(404);
res.end();
}
}).listen(1337, '127.0.0.1');
*/
var express = require('express');
var app = express();
var mysql = require('mysql');
var apiController = require('./controllers/apiController');
var htmlController = require('./controllers/htmlController');
var port = process.env.PORT || 3000;
app.use('/assets', express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
app.use('/', function(req, res, next) {
console.log('Request Url:' + req.url);
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'admin',
database: 'nodejs'
});
con.query('SELECT People.id, firstname, lastname, adress from people inner join personadresses on people.id = personadresses.personid inner join adresses on personadresses.adressid = adresses.id',
function(err, rows) {
if (err) throw err;
console.log(rows[1].firstname);
}
);
next();
});
apiController(app);
htmlController(app);
app.listen(port);