generated from alexk111/store-of-something
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
data-collector-currencies.js
43 lines (35 loc) · 1.02 KB
/
data-collector-currencies.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
const https = require("https");
const path = require("path");
const fse = require("fs-extra");
const pathSrc = "./src";
const pathCollected = pathSrc + "/data/_collected";
async function loadCurrenciesFromRemoteAPI() {
const url = "https://openexchangerates.org/api/currencies.json";
return new Promise((resolve, reject) => {
https
.get(url, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", async () => {
try {
const gotData = JSON.parse(body);
const pathOutFile = path.join(pathCollected, "currencies.json");
await fse.writeFile(pathOutFile, JSON.stringify(gotData,null,2));
resolve();
} catch (error) {
reject(error.message);
}
});
})
.on("error", (error) => {
reject(error.message);
});
});
}
async function build() {
console.info("Collecting Currencies data...");
await loadCurrenciesFromRemoteAPI();
}
build();