how to use the mkdirpsync function from fs-extra in javascript

Here is an example of how to use the mkdirpSync function from the fs-extra package to make sure that a directory exists:

index.tsx
const fs = require('fs-extra');

try {
  fs.mkdirpSync('/path/to/directory');
} catch (err) {
  console.error(err);
}
118 chars
8 lines

The mkdirpSync function will create the directory at /path/to/directory, including any necessary parent directories. If the directory already exists, it will not be modified in any way.

Note that the mkdirpSync function is synchronous, which means that it will block the event loop until the directory has been created. If you need to create directories asynchronously, you can use the mkdirp function instead.

gistlibby LogSnag