From fd5c7cc20d96154b209349398e209afa4e4542ee Mon Sep 17 00:00:00 2001 From: Florian Reuschel Date: Fri, 17 Feb 2017 17:15:34 +0100 Subject: [PATCH] Document the return value of ensureDir This feature is implemented in mkdirp and verified in the mkdirp tests. Just adding it to documentation. --- docs/ensureDir.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/ensureDir.md b/docs/ensureDir.md index ac704e0f..08f31199 100644 --- a/docs/ensureDir.md +++ b/docs/ensureDir.md @@ -18,3 +18,18 @@ fs.ensureDir(dir, function (err) { // dir has now been created, including the directory it is to be placed in }) ``` + +--- + +The callback receives a second argument, containing the path to the first directory that was created in the process. If no directories were made, this will be `null`. +```js +var fs = require('fs-extra') + +// Let's assume that /var/www exists + +var dir = '/var/www/this/path/does/not/exist' +fs.ensureDir(dir, function (err, created) { + console.log(created) // => /var/www/this + // second argument contains the first directory in the path that did not exist before +}) +```