Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (48 loc) · 1.38 KB
/
Copy pathindex.js
File metadata and controls
64 lines (48 loc) · 1.38 KB
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
const express = require('express');
const app = express();
app.use(express.json());
const db = require('./models');
const User = db.User;
const cors = require('cors');
app.use(cors({
origin: 'http://localhost:3001'
}));
app.post('/check',(req,res)=>{
res.send("David"+req.body.id)
})
app.post('/insert',(req,res)=>{
User.create({
Name:req.body.name,
Mobile:req.body.mobile
}).then((data)=>{
res.send(data);
}).catch((err)=>{
console.log(err);
})
})
app.get('/listall',(req,res)=>{
User.findAll({})
.then((data)=>
res.send(data)
).catch((err)=>{
console.log(err);
})
})
app.post('/update',(req,res)=>{
User.update({Mobile:req.body.Mobile,Name:req.body.Name},{where:{id:req.body.id}}).then((data)=>{
data==1?res.send({"message":"Update Successfull"}):res.send({"message":"Unsuccessfull"})
}).catch((err)=>{
console.log(err);
})
})
app.post('/delete',(req,res)=>{
User.destroy({where:{id:req.body.id}}).then((data)=>{
data==1?res.send({"message":"Successfully Deleted"}):res.send({"message":"Unsuccessfull"})
})
})
db.sequelize.sync().then((req)=>{
let port = process.env.PORT || 3000;
app.listen(port,()=>{
console.log("Server...");
})
})