Hey /r/nodeI've posted this over in Stack Overflow http://ift.tt/2Bx1R6j I thought I might have an easier time here at Reddit. I'm trying to make an asynchrous parser, and I can't understand how I'm supposed to structure my class to await the data. Any help would be greatly appreciated. Some code:const fs = require('fs') class CSV { constructor (fileName, buffer) { this.fileName = fileName; this.buffer = buffer; } async parseCSV () { let csv = this.fileName let buff = this.buffer let stream = fs.readFile(csv, buff, (err, data) => { if (err) console.log(err) data = data.split('\r').toString().split('\n') return data }) console.log('---') console.log(await stream) return stream } } let test = new CSV('./topsongs.csv', 'utf8') let data = test.parseCSV().then(res => { console.log(res) }) // console.log(data) module.exports = CSV
Submitted January 27, 2018 at 09:11PM by hiphophipp0
No comments:
Post a Comment