-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (46 loc) · 1.41 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
var express = require('express');
var app = express();
var mongoJS = require('mongojs');
var db = mongoJS('mongodb://jpmean:[email protected]:55495/contactwee',['contactwee']);
var bodyparser = require('body-parser');
app.use(express.static(__dirname + '/public'));
app.use(bodyparser.json());
app.get('/contact',function(req,res){
db.contactwee.find(function (err, docs) {
//console.log(docs);
res.json(docs);
});
});
app.post('/contact',function(req,res){
db.contactwee.insert(req.body, function(err,docs){
res.json(docs);
});
});
app.delete('/contact/:id',function(req,res){
var id = req.params.id;
db.contactwee.remove({_id: mongoJS.ObjectId(id)}, function(err, docs){
res.json(docs);
});
});
app.get('/contact/:id', function(req, res){
var id = req.params.id;
db.contactwee.findOne({_id: mongoJS.ObjectId(id)}, function(err , docs){
res.json(docs);
});
});
app.put('/contact/:id', function(req,res){
var id = req.params.id;
db.contactwee.findAndModify({
query : {_id: mongoJS.ObjectId(id)},
update:{$set:{name:req.body.name,email:req.body.email,phoneno:req.body.phoneno,skype:req.body.skype,address:req.body.address,place:req.body.place,whatsapp:req.body.whatsapp}},new:true},
function(err, docs){
res.json(docs);
});
});
app.listen(process.env.PORT || 3000, function(err) {
if(err) {
console.log(err);
} else {
console.log("Server Running");
}
});