Nodejs 16 does not support fetch()

This commit is contained in:
Raymond Hill 2022-09-06 15:05:01 -04:00
parent 84ab5dbb66
commit e420b75b91
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 3 deletions

View File

@ -24,6 +24,7 @@
/******************************************************************************/ /******************************************************************************/
import fs from 'fs/promises'; import fs from 'fs/promises';
import https from 'https';
import process from 'process'; import process from 'process';
import rulesetConfigs from './ruleset-config.js'; import rulesetConfigs from './ruleset-config.js';
@ -110,9 +111,19 @@ async function main() {
const rulesetDirPromise = fs.mkdir(`${rulesetDir}`, { recursive: true }); const rulesetDirPromise = fs.mkdir(`${rulesetDir}`, { recursive: true });
const fetchList = url => { const fetchList = url => {
return fetch(url) return new Promise((resolve, reject) => {
.then(response => response.text()) https.get(url, response => {
.then(text => ({ name: url, text })); const data = [];
response.on('data', chunk => {
data.push(chunk.toString());
});
response.on('end', ( ) => {
resolve({ name: url, text: data.join('') });
});
}).on('error', error => {
reject(error);
});
});
}; };
const readList = path => const readList = path =>