1

The following code does not create a new directory, nor does it output any err

const fs = require("fs-extra");

fs.mkdir(dirPath, { recursive: true }, (err) => {
  if (err) {
    console.log("ERR: When attempting to mkdir", err);
  } else {
    console.log("MKDIR made " + dirPath);
  }
  cb(null, dirPath);
});

I would expect the directory to be created... or an error.

When I console.log(err) I find that the value of err is null.

How can I ensure this directory has been created?

Kartikey
  • 4,516
  • 4
  • 15
  • 40
lowcrawler
  • 6,777
  • 9
  • 37
  • 79
  • Please provide a specific directory example and tells us what exists before and after your call. You'd likely get more traction with an answer if you provide a [minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example). – jfriend00 Sep 24 '21 at 16:11
  • Can you try the same code with `require('fs');` instead of `require('fs-extra');`? – jabaa Sep 24 '21 at 16:14
  • _"Calling `fs.mkdir()` when `path` is a directory that exists results in an error only when `recursive` is `false`."_ [Node.js](https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback) Is this the case? – jabaa Sep 24 '21 at 16:19
  • I switched to ensureDir and all works fine. – lowcrawler Sep 26 '21 at 20:34

0 Answers0