-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
33 lines (25 loc) · 822 Bytes
/
web.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
var express = require('express');
var Datastore = require('nedb');
var bodyParser = require('body-parser')
var app = express();
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
app.get('/highscore', function(req, res){
db.find({}).sort( {score: -1}).exec(function (err, docs) {
res.send(docs.splice(0, 5));
});
});
app.post('/highscore', function(req, res){
var doc = req.body;
doc.score = parseInt(doc.score, 10);
if (data.score) {
db.insert(doc);
}
res.send(200);
});
var db = new Datastore({ filename: 'datafile', autoload: true });