2016-09-17 02:08:42 +00:00
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
|
|
var MongoClient = require('mongodb').MongoClient, assert = require('assert');
|
|
|
|
var url = 'mongodb://localhost:27017/dat3holdetstime';
|
|
|
|
|
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
app.use(express.static(__dirname + '/static'));
|
|
|
|
|
|
|
|
var mongodb;
|
|
|
|
|
|
|
|
// Connect to mongodb
|
|
|
|
MongoClient.connect(url, function(err, db) {
|
|
|
|
assert.equal(null, err);
|
|
|
|
console.log("Connected succesfully to Mongo server");
|
|
|
|
mongodb = db;
|
|
|
|
});
|
|
|
|
|
|
|
|
var getdata = function(callback) {
|
|
|
|
var collection = mongodb.collection("klandringer");
|
|
|
|
var cursor = collection.find();
|
|
|
|
cursor.toArray(function(err, result) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
} else {
|
2016-09-17 11:27:44 +00:00
|
|
|
result.sort();
|
|
|
|
result.reverse();
|
|
|
|
// for(var i = 0; i < result.length; i++) {
|
|
|
|
// klanddata[result[i]['date']] = result[i]['data'];
|
|
|
|
// }
|
|
|
|
callback(result);
|
2016-09-17 02:08:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
getdata(function(result) {
|
|
|
|
res.render("klandringer", {data:result});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.listen(35211, function () {
|
|
|
|
console.log('Server listening on port 35211!');
|
|
|
|
});
|