I have the following code:
for (var i = 0; i < files.length; i++) {
var data = fs.readFileSync(files[i]);
fs.appendFileSync("file_part", data);
}
Let's say I have 1000 files. Is it the for loop async? Or My application will wait until it will finish the process?
If it sync, how I make it async? so each iterate will be async?
Edit:
This code is part of a server code, using express. We get a lot of https request, and serves the client. One of the operation is to appends files of 1MB to one big file. The server should return 200 if the operation success, 500 otherwise.
The problem is that if the code above (the for loop) is executed, The express module stop serving other clients, and it "busy" with this request. I try to use async.eachSeries (because the order of the files has a meaning, so I have to use Series method), but it still stucks the server.
)there. Does this code even run?