-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy paths6_download_db.js
More file actions
46 lines (38 loc) · 973 Bytes
/
s6_download_db.js
File metadata and controls
46 lines (38 loc) · 973 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
39
40
41
42
43
44
45
/*
* 2020/3/23 Kyuho Kim
* ekyuho@gmail.com
* GET으로 호출하는 경우.
* http://localhost:8083/data
*/
var express = require('express');
var app = express();
mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'me',
password: 'mypassword',
database: 'mydb'
})
connection.connect();
app.get("/data", function(req, res) {
console.log("param=" + req.query);
var qstr = 'select * from sensors ';
connection.query(qstr, function(err, rows, cols) {
if (err) {
throw err;
res.send('query error: '+ qstr);
return;
}
console.log("Got "+ rows.length +" records");
html = ""
for (var i=0; i< rows.length; i++) {
html += JSON.stringify(rows[i]);
}
res.send(html);
});
});
var server = app.listen(8083, function () {
var host = server.address().address
var port = server.address().port
console.log('listening at http://%s:%s', host, port)
});