Answer the question
In order to leave comments, you need to log in
Why is node-csvtojson returning an empty utility object instead of a processed result?
Greetings to the omnipotent mind, I appeal to you not for the last time, but not for the very first.
I promise that I resort to the help of the universal mind only when necessary, after trying to figure it out myself.
There is a certain node-csvtojson
It works asynchronously. But synchronously does not want to.
The examples have the following code:
const csvFilePath='<path to csv file>'
const csv=require('csvtojson')
// Async / await usage
const jsonArray=await csv().fromFile(csvFilePath);
console.log( jsonArray); <--- вещает служебный обект окоянный, а не json как было обещано
Converter { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: null, ended: false, endEmitted: false, reading: false, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, destroyed: false, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, domain: null, _events: { end: [ [Object], [Function] ], prefinish: [Function: prefinish], error: [Function] }, _eventsCount: 3, _maxListeners: undefined, _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: false, errorEmitted: false, bufferedRequestCount: 0, corkedRequestsFree: { next: null, entry: null, finish: [Function: bound onCorkedFinish] } }, writable: true, allowHalfOpen: true, _transformState: { afterTransform: [Function: bound afterTransform], needTransform: false, transforming: false, writecb: null, writechunk: null, writeencoding: null }, _options: {}, param: { constructResult: true, delimiter: ';', ignoreColumns: [], includeColumns: [], quote: '"', trim: true, checkType: false, toArrayString: false, ignoreEmpty: false, workerNum: 1, fork: false, noheader: true, headers: [ 'drvId', 'drvFullName', 'tripId', 'class', 'trpDateBegin', 'trpDateEnd', 'startPoint', 'getFromClient', 'drvTaxTotals', 'diff', 'teaCash', 'coupon', 'payType', 'fullTeaCash', 'TaxFDrvWTeaCash', 'pwgReward', 'trpDuration', 'waitTime', 'endPoint', 'distance', 'parkPrice', 'totalActionPrice' ], flatKeys: false, maxRowLength: 0, checkColumn: false, escape: '"', colParser: {}, _columnConv: [], _headerType: [], _headerTitle: [], _headerFlag: [], _headers: null, _needFilterRow: false, _options: {} }, started: false, recordNum: 0, lineNumber: 0, _csvLineBuffer: '', lastIndex: 0, flushCb: null, processEnd: false, sequenceBuffer: [], _needJson: null, _needEmitResult: null, _needEmitFinalResult: null, _needEmitHeader: null, _needEmitJson: null, _needPush: null, _needEmitCsv: null, _csvTransf: null, finalResult: [] }
Answer the question
In order to leave comments, you need to log in
await must be inside an async function
(async () => {your code...})()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question