-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
33 lines (26 loc) · 805 Bytes
/
server.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
function onRequest(request, response) {
response.writeHead(200, {"Context-Type" : "application/json"});
var timeSeries = createTimeSeries();
var json = JSON.stringify(timeSeries);
response.write(json);
response.end();
}
function createTimeSeries() {
var data = [];
var yourDate = new Date();
for(var i = 0; i < 10; ++i) {
var sample = {
timestamp : new Date(yourDate.getFullYear(), yourDate.getMonth() - i, 1).getTime(),
value : Math.floor(Math.random() * 100) + 1
}
data.push(sample);
}
var timeSeries = {
data : data
}
return timeSeries;
}
var http = require('http');
var port = 8888;
http.createServer(onRequest).listen(port);
console.log("Server listening on port " + port);