Monday, 10 February 2020

How to make this Asynchronous only using callbacks?

const fs = require("fs"); const n = 12; let output_path; const content = "Data-1"; const writing = function(text, callback){ fs.writeFile(output_path, text, function(err){ if(err){ console.log(err); } else{ callback(); } }); } const callback = function(){ console.log(`Done! Filename is: ${output_path}`); } for(let i = 1; i <= n; i++){ output_path = `./${i}-output.txt`; writing(content, callback); }

Submitted February 11, 2020 at 04:29AM by Gaffer123

No comments:

Post a Comment