-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
38 lines (32 loc) · 965 Bytes
/
app.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
const http = require('http');
const url = require('url');
const FixerIO = require('fixer-io-utility');
const server = http.createServer();
/**
* @example
* This is an example of how the fixer IO utility class
* can be leveraged to make requests to the API.
* @example
*/
const fixerUtility = new FixerIO('put-your-api-key-here');
fixerUtility.request('latest').then((response) => {
console.log(response);
});
server.on('request', (request, response) => {
response.writeHead(200, {'Content-Type': 'application/json'});
const query = url.parse(request.url, true).path;
http.get('http://data.fixer.io' + query, (res) => {
let buffer = "";
res.on('data', (chunk) => {
buffer += chunk;
});
res.on('end', () => {
response.write(buffer);
response.end();
});
});
});
const port = process.env.PORT || 8080;
server.listen(port);
console.log("Listening on port " + port + "......")
module.exports = {FixerIO, server}