Open tengotengo opened 5 months ago
const { parse } = require('csv-parse'); const fs = require('fs');
const parser = parse(fs.readFileSync('./data2.csv').toString(), { }, function (err, records) { console.log(111, 're111cords', records); });
data2.csv:
102,10790 WILSHIRE BLVD,Los Angelse,CA,90024 104,1005 N 4TH STREET,Montebello,CA,90640
output:
111 re111cords [ [ ' 102', '10790 WILSHIRE BLVD', 'Los Angelse', 'CA', '90024' ], [ '104', '1005 N 4TH STREET', 'Montebello', 'CA', '90640' ] ]
When copy/pasting your code above into vscode, I can see an invisible character in your sample:
It might be becase you are sourcing an utf-8 file with a leading BOM inside. Try adding the {bom: true} option.
{bom: true}
const { parse } = require('csv-parse'); const fs = require('fs');
const parser = parse(fs.readFileSync('./data2.csv').toString(), { }, function (err, records) { console.log(111, 're111cords', records); });
data2.csv:
102,10790 WILSHIRE BLVD,Los Angelse,CA,90024 104,1005 N 4TH STREET,Montebello,CA,90640
output:
111 re111cords [ [ ' 102', '10790 WILSHIRE BLVD', 'Los Angelse', 'CA', '90024' ], [ '104', '1005 N 4TH STREET', 'Montebello', 'CA', '90640' ] ]