lib/storage/filesystem.js
function writeToFile(file) {
	if (!writeQueue[file]) {
		return;
	}

    // If not already saving then save, but using the object we make sure to take only
    // the last changes.
    // Truncate - https://stackoverflow.com/questions/35178903/overwrite-a-file-in-node-js
    fs.truncate(file, err => {
        const beforeSaveVersion = writeQueue[file].version;
        fse.outputJson(file, writeQueue[file].db, err => {
			// Something has been saved while the filesystem was writing to file then
			// save again
            if (beforeSaveVersion !== writeQueue[file].version) {
                writeToFile(file);
            }

            resolveAllWriteQueueCallbacks(file, err);
            delete writeQueue[file];
        });
    });
}
function writeToFile(file) {
	if (!writeQueue[file]) {
		return;
	}

    // If not already saving then save, but using the object we make sure to take only
    // the last changes.
    // Truncate - https://stackoverflow.com/questions/35178903/overwrite-a-file-in-node-js
    fs.truncate(file, err => {
        const beforeSaveVersion = writeQueue[file].version;
        fse.outputJson(file, writeQueue[file].db, err => {
			// Something has been saved while the filesystem was writing to file then
			// save again
            if (beforeSaveVersion !== writeQueue[file].version) {
                writeToFile(file);
            }

            resolveAllWriteQueueCallbacks(file, err);
            delete writeQueue[file];
        });
    });
}
function writeToFile ( file ) { if ( ! writeQueue [ file ] ) { return ; } // If not already saving then save, but using the object we make sure to take only // the last changes. // Truncate - https://stackoverflow.com/questions/35178903/overwrite-a-file-in-node-js fs . truncate ( file , err => { const beforeSaveVersion = writeQueue [ file ] . version ; fse . outputJson ( file , writeQueue [ file ] . db , err => { // Something has been saved while the filesystem was writing to file then // save again if ( beforeSaveVersion !== writeQueue [ file ] . version ) { writeToFile ( file ) ; } resolveAllWriteQueueCallbacks ( file , err ) ; delete writeQueue [ file ] ; } ) ; } ) ; }
Save db data to a file from the write queue.

@param {string} file File path.
@returns {void} Nothing
Save db data to a file from the write queue .