-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.js
38 lines (32 loc) · 952 Bytes
/
sync.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
'use strict';
const fs = require('fs');
const {promisify} = require('util');
const got = require('got');
const writeFile = promisify(fs.writeFile);
const gtldsURL = 'https://www.icann.org/resources/registries/gtlds/v2/gtlds.json';
const COMPLETED = 'Finished syncing. {count} saved.';
const ERROR_FETCHING = 'Error fetching gTLDs.';
const ERROR_SAVING = 'Error saving file';
(async () => {
try {
const gtlds = [];
const response = await got(gtldsURL, {json: true});
response.body.gTLDs.map(({
contractTerminated,
gTLD,
registryOperator
}) => gtlds.push({
contractTerminated,
gTLD,
registryOperator
}));
try {
await writeFile('gtlds.json', JSON.stringify(gtlds));
console.log(COMPLETED.replace('{count}', gtlds.length));
} catch (error) {
console.log(ERROR_SAVING, error);
}
} catch (error) {
console.log(ERROR_FETCHING, error.response.body);
}
})();