I'm trying to read a csv file using node.js. I'm getting the error "unexpected end of input". The following is the code I've used:
const csv = require('csv-parser');
const fs = require('fs');
const fast = require('fast-csv');
fs.createReadStream('filename.csv')
.pipe(csv())
.on('data', (row) => {
console.log(row);
})
.on('end', (row) => {
console.log('CSV file successfully processed');
I've taken the code from here.
when I run the above code in command mode using "node sample.js", the following is the error:
C:\Users\learningsql\Desktop\filter>node sample.js
C:\Users\learningsql\Desktop\filter\sample.js:12
console.log('CSV file successfully processed');
SyntaxError: Unexpected end of input
[90m at wrapSafe (internal/modules/cjs/loader.js:1047:16)[39m
[90m at Module._compile (internal/modules/cjs/loader.js:1097:27)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:977:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:877:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)[39m
[90m at internal/main/run_main_module.js:18:47[39m
Any help is appreciated. Thanks.
const parse = require('csv-parse'); const fs = require('fs'); const csvData= []; fs.createReadStream(__dirname + '/filename.csv') .pipe( parse({ delimiter: ',' }) ) .on('data', function (dataRow) { csvData.push(dataRow); }) .on('end', function () { console.log(csvData); });});.