In node.js, how do I generate a unique temporary file name, a la mkstemp(3)
? I want to atomically write a file using fs.rename
.
var tmp = require('tmp'); var tmpObj = tmp. fileSync({ mode: 0644, prefix: 'projectA-', postfix: '. txt' }); console. log("File: ", tmpObj.name); console.
In Node. js, you can use the fs. unlink() method provided by the built-in fs module to delete a file from the local file system.
Method # 1 – Use the mktemp or tempfile utility to create temporary random file name. The script or command should quit if it didn't get a safe temporary file using the exit command.
Most TMP files are not meant to be opened. While you can open a TMP file in Microsoft Notepad (Windows) or another text editor, the file may not be human-readable. Typically, TMP files are deleted after either: The application that created the file finishes using the file.
Another popular package is tmp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With