-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.js
57 lines (49 loc) · 1.63 KB
/
backup.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
var _ = require('lodash');
var express = require('express');
var app = express();
//var tools = require('./functions.js')
var fs = require("fs");
//var filename = "containers.json"
var content = fs.readFileSync("db.json");
content = JSON.parse(content);
app.get('/api/games', function (request, response) {
var method = 'callback';
if (request.query.method == "promise") {
method = 'promise';
}
//console.log(method);
if (method == 'callback'){
fs.readFile(filename, function (err, result) {
if (err) {
response.status(500).send("didn't work try another path");
}
else {
var containers = JSON.parse(result);
//console.log("Output Content : \n"+ array);
var array = [];
for (var container in containers) {
array.push(new Date(containers[container].created));
}
if (!process.env.USE_LODASH)
array.sort(function (date1, date2) {
if (date1 > date2) return 1;
if (date1 < date2) return -1;
return 0;
});
else {
array = _.sortBy(array, function (value) {
// console.log(value.getTime());
return value.getTime();
})
}
response.send(array);
}
});
}
else {
}
});
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
})