-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·35 lines (30 loc) · 1.17 KB
/
server.js
File metadata and controls
executable file
·35 lines (30 loc) · 1.17 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
/**
* Created by Akshay on 3/4/2015.
*/
var express = require("express");
var MongoClient = require("mongodb").MongoClient;
var cors = require("cors");
var app = express();
app.use(cors());
/** app.get('/people', function (req, res) {
Person.find(function (err, doc) {
res.send(doc);
})
}); **/
//modify req to include username, to determine collection
app.post('/send_character', function(req, res, next){ //req variable is a JSON document
MongoClient.connect('mongodb://localhost:27017/moneysense', function(err, db) {
if(err) throw err;
if(typeof db.collection('characters').find({access_token: req.access_token}) === 'object') {
db.collection('characters').update({access_token: req.access_token}, req, function(err, inserted) {
if(err) throw err;
return db.close();
}); //pass in stored JSON document
//if not, create array
} else {
//find sports and make them into arrays; stores as req1
db.collection('characters').insert(req);
}
});
});
app.listen(3000);