const stations = require('db-stations') const fs = require('fs'); var ds100list = {}; var ds100reverseList = {}; stations.full() .on('data',function(station){ var stuff = []; station.ril100Identifiers.forEach(element => { stuff.push(element.rilIdentifier) ds100list[element.rilIdentifier] = station.id; }) if (stuff.length === 0) return; ds100list[station.id] = stuff.join(', '); }) .on('end',function(){ fs.writeFile("ds100.json", JSON.stringify(ds100list), () => {}) fs.writeFile("ds100reverse.json", JSON.stringify(ds100reverseList), () => {})a });