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 https from 'https';
import process from 'process';
import rulesetConfigs from './ruleset-config.js';
@ -110,9 +111,19 @@ async function main() {
const rulesetDirPromise = fs.mkdir(`${rulesetDir}`, { recursive: true });
const fetchList = url => {
return fetch(url)
.then(response => response.text())
.then(text => ({ name: url, text }));
return new Promise((resolve, reject) => {
https.get(url, response => {
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 =>