为每个循环创建数据并将数据写入文件时出错?

时间:2019-04-19 11:06:31

标签: node.js for-loop async-await

在我的nodejs文件中,我正在从xml(100个学生数据)文件中获取批量数据,并将其分成单个文件。所以问题是每个学生数据都需要写在单个文件上,而我的foreach循环不是在等待写所有文件,而是因为我的nodemon重新启动了?

jaison.pbcu.student.forEachAsync(i => {
                    var otherData = JSON.stringify(jaison.pbcu.student[i]);
                        var leaff = SHA256(jaison.pbcu.student[i]);
                        var prooff = tree.getProof(leaff)

                        var writeStream = await fs.createWriteStream(path1 + "/public/issued_json/"+name+".json");
                        await writeStream.write("{");
                        await writeStream.write("\"employee\":[");
                        await writeStream.write(otherData);
                        await writeStream.write("],");
                        await writeStream.write("\n");
                        await writeStream.write("\"proof\":{");
                        await writeStream.write("\"path\":",prooff);
                        await writeStream.write(",");
                        await writeStream.write("\"root\":");
                        await writeStream.write(",");
                        await writeStream.write("\"transaction_id\":");
                        await writeStream.write("}");
                        await writeStream.write("}");
                        await writeStream.end();
                        var name = await jaison.pbcu.student[i].regno.$t;
                        var fullname = name+".json"
                        json_array.push([fullname,universal_id]);

                });

0 个答案:

没有答案