P
P
pomaz_andrew2019-02-06 15:56:21
Node.js
pomaz_andrew, 2019-02-06 15:56:21

How to write multiple files asynchronously in a NodeJS application?

Good day everyone!
The application has a need to asynchronously write multiple files, the names are in an array
. I'm trying to do this

for (var l = 0; l < self.contentHyperLinks.length; l++) {
      var _nameChapter = config.out_folder + getNameChapter(self.contentListItems[l]);
      var chapter_stream = Fs.createWriteStream(_nameChapter); 
      chapter_stream.once('open', function (fd) {
          chapter_stream.write(self.contentHyperLinks[l]));
          chapter_stream.end();
      });
}

And you also need to create a function that
is executed after writing the file names from the array.
How can I rewrite this part of the application - using RxJS (forkJoin for example)
or using file write promisification as an option? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question