To use mkdtemp function from fs-extra library in TypeScript, we first need to install the fs-extra library and its type definitions.
44 chars2 lines
After installing the library and the types, we can import the functions from the library and use it as follows:
index.ts261 chars11 linesHere, we are using the mkdtemp function from the fs-extra library to create a temporary directory with a given prefix. Since the mkdtemp function returns a callback with an error and the new directory path, we use promisify function from util module to convert it to an async function that returns Promise.
With the createTempDir function, we can call mkdtemp function asynchronously and it will return the generated temporary directory path.
Note: The mkdtemp function creates a unique temporary directory with the prefix passed as argument and replaces six characters of that prefix with random symbols.
gistlibby LogSnag