-
Notifications
You must be signed in to change notification settings - Fork 2
/
listuser.js
49 lines (36 loc) · 1.18 KB
/
listuser.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
var express = require('express');
var app = express();
var fs = require("fs");
var mysql = require('mysql');
var bodyParser = require('body-parser');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "root",
database: "HSC_Lib"
});
app.use(bodyParser.json())
app.get('/listUsers', function (req, res) {
fs.readFile( __dirname + "/" + "user.json", 'utf8', function (err, data) {
//var jsondata = req.body;
console.log(req.data)
var values = [];
console.log(values)
for(var i=0; i< data.length; i++)
values.push([data[i].name,data[i].password,data[i].profession,data[i].id]);
console.log(values)
//connection.query('INSERT INTO members (name , password , profession ,id) VALUES ?', [values])
//var sql = "INSERT INTO BLE_info (name , password , profession ,id) VALUES ?', [data]";
con.query("SELECT * FROM BLE_info", function (err, result) {
if (err) throw err;
//console.log(result);
})
//console.log( data );
res.end( data );
});
});
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})