Adding Data to Event Emitter

Keywords´╝Ü javascript eventemitter


I am using "proxy-lists": "^1.16.0" package to obtain proxies.

I would like to save all incoming Array-Objects into my own array to later save it to the db.

When running the below example my array is empty and no file is written:

const ProxyLists = require('proxy-lists');
const fs = require('fs');

global.__basedir = __dirname;

const options = {
    countries: null

// `gettingProxies` is an event emitter object.
const gettingProxies = ProxyLists.getProxies(options);

const data = []
gettingProxies.on('data', function (proxies) {

gettingProxies.on('error', function (error) {

gettingProxies.once('end', function () {
    fs.writeFile(__basedir + "data/file.txt", data, function (err) {
        if (err) {
            return console.log(err);
        console.log("The file was saved!");

Any suggestions what I am doing wrong?

I appreciate your replies!