-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
32 lines (27 loc) · 980 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
var express = require('express');
var fs = require('fs');
var https = require('https');
// Creates server instance
var app = express();
//create the HTML page and send to the host
app.get('/', function(req, res) {
https.get('https://www.anychart.com/products/anystock/data/feed/?key[]=AAPL.US&format=json&kind=eod', function(response) {
var data = '';
// wait for the whole answer
response.on('data', function(chunk) {
data += chunk;
});
// when the answer is ready
response.on('end', function() {
// For this demo we are using a fs.readFileSync and string replace methods to render the page
var chartTemplate = fs.readFileSync(__dirname + '/index.html').toString();
var page = chartTemplate.replace("'{{data}}'", data);
res.send(page);
});
});
});
var port = process.argv[2] || 8080;
// Runs express server
app.listen(port, function() {
console.log('Example app is listening on localhost:' + port + '\n');
});