Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs - Temporary file name

Tags:

node.js

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.

like image 896
nornagon Avatar asked Aug 14 '11 04:08

nornagon


People also ask

How to create a temporary file in nodejs?

var tmp = require('tmp'); var tmpObj = tmp. fileSync({ mode: 0644, prefix: 'projectA-', postfix: '. txt' }); console. log("File: ", tmpObj.name); console.

How do I delete a FS file?

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.

How do I create a temp file in bash?

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.

What do I do with a tmp file?

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.


1 Answers

Another popular package is tmp.

like image 95
Steve Jansen Avatar answered Sep 29 '22 01:09

Steve Jansen