-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (31 loc) · 945 Bytes
/
test.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
var express = require('express');
var app = express();
var mysql = require('mysql');
var bodyParser = require('body-parser')
app.set("view engine", "ejs");
app.set("views", "public");
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use('/node_modules', express.static(__dirname + '/node_modules'));
var con = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'tung'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
app.listen(3000);
app.get('/',function(req,res){
con.query('SELECT * from persons', function(err, rows, fields) {
const data = JSON.parse(JSON.stringify(rows));
// console.log(data);
res.render('home.ejs', {user: data});
});
});
app.post('/tung', function(req, res) {
con.query('insert into persons values (' + req.body.id + "," + req.body.name + ')');
res.send('hello');
})