-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (42 loc) · 1.17 KB
/
app.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
const express =require('express')
var app =express();
const connection = require('./db');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//get api
app.get('/get',(req,res) => {
res.send("hello there");
})
//post method
app.post('/addUser',(req,res) => {
console.log(req.body);
var postData = {
"name" : req.body.name,
"age" : req.body.age,
"mobile_number" : req.body.mobile_number
};
connection.query('insert into users.user set ? ', postData, function(err,result){
if(err)
console.log(err);
else{
console.log("inserted")
res.send("data added successfully!!")
}
})
// http put method
app.put('/update/:id',(req,res) => { // path param
var id = req.params.id;
connection.query('update users.user set mobile_number = ? where id = ? ', [req.body.mobile_number,id] , function(err,result){
if(err){
console.log(err);
res.send(err);
}
else{
console.log("upadted");
res.send("data got updated!");
}
})
})
})
app.listen(8085);