-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (46 loc) · 1.18 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
49
50
51
52
53
54
55
56
57
58
59
60
61
var express = require('express')
var app = express();
var bodyParser = require('body-parser')
var mongojs = require('mongojs');
var mclient = require('mongodb').MongoClient;
const CONFIG={};
CONFIG.dburl = 'mongodb://Ilankumaran-developer:[email protected]:21955/tripwell'
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/login',(req,res)=>{
var db = ''
mclient.connect(CONFIG.dburl,(err,database)=>{
db = database;
db.collection('users').find({$and:[{"username":req.body.username},{"password":req.body.password}]}).toArray(function(err,dat){
if(err)
console.log(err);
else{
console.log(dat)
res.send(dat);
}
});
})
})
app.post('/register',(req,res)=>{
var db = ''
mclient.connect(CONFIG.dburl,(err,database)=>{
db = database;
db.collection('users').insert(req.body,(err,doc)=>{
if(err){
console.log(err);
res.send({success:'0'});
}
else{
console.log(doc)
console.log('success');
res.send({success:'1','_id':doc.ops[0]._id});
}
})
})
})
app.get('/aaa',(req,res)=>{
res.send('Hello World')
})
app.listen(process.env.PORT || 3005,function(){
console.log('helllo world')
})