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

To use the mkdirs function from the fs-extra package in Node.js, you can follow the below steps:

  1. Install the fs-extra package using npm:
npm install fs-extra
21 chars
2 lines
  1. Import the fs-extra module and use the mkdirs function to create a folder:
index.tsx
const fs = require('fs-extra');

const folderPath = './myFolder';

fs.mkdirs(folderPath, (err) => {
  if (err) {
    console.error(err);
  } else {
    console.log(`Folder created successfully at ${folderPath}`);
  }
});
221 chars
12 lines

In the above example, we have provided the path of the folder that we want to create, which is ./myFolder. The mkdirs function takes two arguments - the path of the folder to create and a callback function. If there is an error while creating the folder, the callback function will receive an error object. Otherwise, it will be called with no arguments.

gistlibby LogSnag