Error: write after end when csvConverter.fromString is called two times
See original GitHub issueMy program need to parse two csv files that are stored in a json object :
csv_files = [
{
"name" : "<name>",
"file" : "./file.csv"
},
[...]
]
I use async
to execute some part of my code synchronously. And in my main program I read all file from csv_files
in order to parse all csv.
If I call one time csvConverter.fromString
it’s works perfectly. But when I want to do a loop (something like that) I have Error: write after end
.
With this code :
[...]
allCsv2bdd_url(csv_files[i], function(err){
if(csv_files.length > i){
i++;
allCsv2bdd_url(csv_files[i], function(err){});
}else {
done();
}
});
I have the error message.
In allCsv2bdd_url
I execute two functions in synchronous mode, including the csvtojson
function.
var csvLines = '';
//- Read Lines
try{
fs.readFileSync(csv_file).toString().split('\n').forEach(function (line) {
csvLines += line;
console.log(' [url.csv] '+line);
});
//- Transform lines to json
csvConverter.fromString(csvLines, function(err, jsonObj){
if (err){
console.log('\n [url.csv] An error as occured when trying to convert csv to JSON :\n\t'+err);
callback( );
} else {
callback( jsonObj );
}
});
}catch(e){
console.log('\n [url.csv] /!\\ Cannot access to file '+csv_file+' with the following error :\n\t'+e);
callback( );
}
Is someone can explain why I have this problem ?
Thanks 😃
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
'Write after end' error with Express, csvtojson and node-walk
This assumes that data passed in by the csv converter on 'end_parsed' is always an array. It combines the data from all files...
Read more >Writing to Files in Node.js - Stack Abuse
write when performing fine-grained updates to files, for instance, writing a sequence of bytes at a known position in the middle of a...
Read more >Top 10 Mistakes Node.js Developers Make - AirPair
1 Not using development tools. 1.1 Automating restarts; 1.2 Automatic browser refresh · 2 Blocking the event loop · 3 Executing a callback ......
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
Regardless of how difficult Node.js makes writing safe code, and how easy it makes ... deals with such a scenario, “done” may be...
Read more >Understanding Streams in Node.js - NodeSource
Streams are a way to handle reading/writing files, ... Handle stream events --> data, end, and error ... Like in the following example:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, You have to create new Converter instance for different files. Converter is based on stream. Once a file processing finished, the stream is closed. To process another file, create new converter.
~Keyang
On 21 April 2016 at 09:38, flexbrane notifications@github.com wrote:
Thanks. I will make this better in next version.
~Keyang
On 1 November 2016 at 15:58, Dolan notifications@github.com wrote: