-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
95 lines (73 loc) · 2.3 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Created by Komal on 20/05/15.
*/
var express=require('express');
var app=express();
var mongojs=require('mongojs');
var db = mongojs('EMS',['feature']);
var db1 = mongojs('EMS',['product']);
var monk=require('monk');
var db2 = monk('localhost:27017/EMS');
var bodyParser=require('body-parser');
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());
app.get('/feature',function(req,res){
db.feature.find(function (err,docs) {
res.json(docs);
});
});
app.get('/getProduct',function(req,res){
db1.product.find(function(err,docs){
res.json(docs);
});
});
app.post('/feature',function(req,res){
db.feature.insert(req.body, function (err, doc) {
res.json(doc);
});
});
app.delete('/getProduct/:id', function (req,res) {
var id= req.params.id;
db1.product.remove({_id:mongojs.ObjectId(id)}, function (err, doc) {
res.json(doc);
});
});
app.delete('/feature/:id', function (req,res) {
var id= req.params.id;
db.feature.remove({_id:mongojs.ObjectId(id)}, function (err, doc) {
res.json(doc);
});
});
app.get('/feature/:id',function(req,res){
var id = req.params.id;
db.feature.findOne({_id:mongojs.ObjectId(id)}, function(err,doc){
res.json(doc);
});
});
app.get('/oneProduct/:id',function(req,res){
var id = req.params.id;
db1.product.findOne({_id:mongojs.ObjectId(id)}, function(err,doc){
res.json(doc);
});
});
app.put('/feature/:id',function(req,res){
var id=req.params.id;
db.feature.findAndModify({query:{_id:mongojs.ObjectId(id)},
update:{$set:{featureID:req.body.featureID,featureName:req.body.featureName,featureDescription:req.body.featureDescription}},
new:true}, function (err,doc) {
res.json(doc);
});
});
app.use(function(req,res,next){
req.db2 = db2;
next();
});
app.post('/Product',function(req,res)
{
db1.product.insert(req.body, function (err, doc) {
res.json(doc);
console.log(doc);
});
});
app.listen(3000);
console.log("server is listening on port 3000");