Tag: dump

fs转储相当于NodeJs?

目的 强制fs(以及使用它的库)在终止应用程序之前将所有内容写入文件。 背景 我正在使用npm包csv-write-stream将对象写入CSV文件。 一旦库完成了CSV文件的写入,我想用process.exit()终止我的应用程序。 码 为了达到上述目标,我写了以下内容: let writer = csvWriter({ headers: ['country', 'postalCode'] }); writer.pipe(fs.createWriteStream('myOutputFile.csv')); //Very big array with a lot of postal code info let currCountryCodes = [{country: Portugal, postalCode: '2950-286'}, {country: Barcelona, postalCode: '08013'}]; for (let j = 0; j < currCountryCodes.length; j++) { writer.write(currCountryCodes[j]); } writer.end(function() { console.log('=== CSV written successfully, […]