I have a Task.csv file with the following content:
task1,01/05/2020, 20/05/2020, Active
task2,03/05/2020, 17/05/2020, Active
task3,10/05/2020, 25/05/2020, Active
task4,02/05/2020, 21/05/2020, Active
task5,07/05/2020, 28/05/2020, Active
I want to parse this in JavaScript (NodeJS) and display each line read surrounded by brackets. The following is the code I'm using:
function readCsvFile()
{
var fs = require('fs');
var textByLine = fs.readFileSync('Tasks.csv').toString().split("\n");
var i;<br>
for (i=0; i<textByLine.length; i++)
{
console.log("[" + textByLine[i] + "]");
}
}
What I expect:
[task1,01/05/2020, 20/05/2020, Active]
[task2,03/05/2020, 17/05/2020, Active]
[task3,10/05/2020, 25/05/2020, Active]
[task4,02/05/2020, 21/05/2020, Active]
[task5,07/05/2020, 28/05/2020, Active]
When I run it, the output is:
]task1,01/05/2020, 20/05/2020, Active
]task2,03/05/2020, 17/05/2020, Active
]task3,10/05/2020, 25/05/2020, Active
]task4,02/05/2020, 21/05/2020, Active
[task5,07/05/2020, 28/05/2020, Active]
I'm new to JavaScript and NodeJS so any comment would be helpful, thanks.
\r\ninstead of just\n. Check your text editor it might have a setting you can change to tell it to Use unix style line endings