In Node.js I'm using stream-chain and stream-json to request streaming feeds from local and remote resources. Below works for local resources, but how to modify it, to allow also for external resources? Do I need to download the file first or?
const fs = require('fs');
const { chain } = require('stream-chain');
const Pick = require('stream-json/filters/Pick');
const { streamArray } = require('stream-json/streamers/StreamArray');
const path = './feed.json'; // External URL or local file
const pipeline = chain([
fs.createReadStream(path),
Pick.withParser({ filter: 'products', once: true }), // Custom: modify feed
streamArray(),
data => data
]);
pipeline.on('data', () => {
counter++;
console.log(data);
});
pipeline.on('error', error => console.log(error));
pipeline.on('end', () => console.log(`Found ${counter} entries`));