forked from charu25/SellBuy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbapp-v1.js
94 lines (59 loc) · 1.74 KB
/
sbapp-v1.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
94
express=require("express");
var app=express();
var http = require("http");
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
var fs = require("fs");
var cheerio = require("cheerio");
var assert = require("assert");
app.configure(function() {
app.use(express.static(__dirname));
});
app.use(express.urlencoded());
app.use(express.json());
//app.use(express.multipart());
app.get('/', function(req, res){
res.sendfile(__dirname + '/index.html');
});
app.get('/bids', function(req, res){
res.sendfile(__dirname + '/bids.html');
});
app.post('/profile', function(req, res){
MongoClient.connect('mongodb://localhost:27017/mydb', function(err, db) {
if(err) throw err;
var collection = db.collection('sellbuy');
collection.find({name:req.body.name}).toArray(function(err, results) {
res.send(results);
fs.readFile('/home/charu/nodeprog/sellBuy/profile.html', function (err, data) {
if (err) throw err;
$ = cheerio.load(data);
});
db.close();
});
})
});
app.post('/test',function(req, res){
var ip=req.body;
var data={};
console.log(ip);
for(var attributename in ip){
if(ip[attributename].length>0){
data[attributename]=ip[attributename];
}
}
console.log(data);
MongoClient.connect('mongodb://localhost:27017/mydb', function(err, db) {
if(err) throw err;
var collection = db.collection('sellbuy');
collection.insert(data, function(err, docs) {
collection.count(function(err, count) {
console.log(format("count = %s", count));
});
collection.find().toArray(function(err, results) {
console.dir(results);
db.close();
});
});
})
});
app.listen(3000);