The tmp package with promises support and disposers.
93
A utility that safely updates configuration files using atomic write operations to prevent data corruption during writes.
You need to implement a configuration file update utility that ensures data integrity by using atomic write operations. The utility should:
This pattern (write to temp, then rename) is commonly used for atomic file operations to ensure that readers never see partial writes and the original file is preserved if the write operation fails.
Implement a function updateConfigFile(filePath, newContent) that:
The function should handle the following scenarios:
.tmp extension@generates
/**
* Atomically updates a configuration file with new content.
*
* @param {string} filePath - The path to the configuration file to update
* @param {string} newContent - The new content to write to the file
* @returns {Promise<void>} A promise that resolves when the update is complete
* @throws {Error} If the file cannot be written or renamed
*/
async function updateConfigFile(filePath, newContent) {
// Implementation here
}
module.exports = { updateConfigFile };Provides temporary file management with promise support.
Install with Tessl CLI
npx tessl i tessl/npm-tmp-promisedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10