-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (40 loc) · 1.13 KB
/
server.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
var express = require('express');
var app = express();
var mysql = require('mysql');
var bodyParser = require('body-parser');
app.use(bodyParser.json({type:'application/json'}));
app.use(bodyParser.urlencoded({extended:true}));
var con = mysql.createConnection({
host:'localhost',
// port:'8004',
user:'root',
password:"", //empty for window
database: 'problem'
});
var server = app.listen(4548, function(){
var host = server.address().address
var port = server.address().port
console.log("start");
});
con.connect(function(error){
if(error) console.log(error);
else console.log("connected");
});
app.get('/users_table', function(req, res){
con.query('select * from users_table', function(error, rows, fields){
if(error) console.log(error);
else{
console.log(rows);
res.send(rows);
}
});
});
app.get('/problem', function(req, res){
con.query('select * from `problem`', function(error, rows, fields){
if(error) console.log(error);
else{
console.log(rows);
res.send(rows);
}
});
});