-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.js
72 lines (55 loc) · 1.38 KB
/
test2.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
67
68
69
70
71
72
const express=require('express');
const cors=require('cors');
const mysql=require('mysql');
const app=express();
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
const connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'syam0884',
insecureAuth:true,
database:'employee',
multipleStatement:true
})
const emp='select * from employee';
app.use(cors());
connection.connect(err => {
if (err) {
return err;
}
})
app.get('/',(req,res)=>{
connection.query(emp,(err,results)=>{
if(err){
return res.send(err)
}
else{
return res.json({
data:results
})
}
})
})
app.patch("/",(req,res)=>{
let emp=req.body
console.log(emp);
connection.query("insert into employee values (?)",[req.body.emp],(err,results)=>{
if(!err)
res.send(results)
else
console.log(err);
})
})
app.delete('/:id',(req,res)=>{
connection.query('delete from employee where empid=?',[req.params.id],(err,results)=>{
if(!err)
res.send("delete success")
else
console.log(err);
})
})
app.listen(4000,()=> {
console.log("it is success on port 4000");
})