First I write summarized pseudo code.
const ExcelSheet = new ExcelSheet() // excel.js library
const usersWithPlayedGames = await findAllUsers({ include: GameTable });
for (let i = 0; i < usersWithPlayedGames.length; i++) {
// Write some user data on Excel.
...
...
for (let j = 0; j < usersWithPlayedGames[i].length; j++) {
// Write some user's game on Excel
...
...
for (let k = 0; k < usersWithPlayedGames[i][j].length; k++) {
// Write some users's game's company data on Excel
...
...
}
}
}
res.send(ExcelSheet.toFile());
The actual code is pretty long.
And it take client req => res time almost 15sec.
I know my problem solution is not good.
I can do refactoring with this code.
But the real problem is it blocks another client request.
I search on google and find several solutions.
- Node.js child process spawn.
- Make with a callback function(I don't know exactly how to do).
- Write more than a good algorithm.
What's the concept I'm missing from Node.js?
Please help me with a small favor.
Thank you.
Write some user data on Excel.,Write some user's game on ExcelandWrite some users's game's company data on Excel.... is there an asynchronous way of doing these? Since you haven't shown this code its hard to guess ... but that would solve theblocks another client requestissue