mkdtempSync()
is a function that generates a unique and random directory name from a template string, and creates the directory synchronously. Here's an example of how to use it in Node.js with the fs-extra
library:
index.tsx199 chars9 lines
In the example above, the mkdtempSync()
function is used to create a temporary directory within the /tmp
directory with a prefix of myapp-
. The function returns the path of the created directory, which is then logged to the console.
Note that mkdtempSync()
is a synchronous function that blocks the main thread until the directory is created. It's recommended to use the asynchronous mkdtemp()
function in production code to avoid blocking the event loop.
index.tsx195 chars9 lines
The asynchronous version of the mkdtemp()
function returns a Promise that resolves with the path of the created directory. You can also use mkdtemp
with a callback function if you prefer.
gistlibby LogSnag