how to use the mkdirp function from the fs-extra library in typescript

To use mkdirp function from fs-extra library in Typescript, you need to first install the library using npm:

index.ts
npm install --save fs-extra
28 chars
2 lines

After that, you need to import the library in your Typescript file:

index.ts
import * as fs from 'fs-extra';
32 chars
2 lines

Now, you can use the mkdirp function to create a directory recursively:

index.ts
const path = '/path/to/my/directory';
fs.mkdirp(path, (err) => {
  if (err) {
    console.error(err);
  } else {
    console.log(`Directory created at ${path}.`);
  }
});
171 chars
9 lines

The mkdirp function takes two parameters: the path of the directory to be created and a callback function. The callback function is called with an error object if there is an error creating the directory. If the directory is created successfully, the callback function is called with no arguments.

gistlibby LogSnag