Gathering detailed insights and metrics for mkdirp
Gathering detailed insights and metrics for mkdirp
Gathering detailed insights and metrics for mkdirp
Gathering detailed insights and metrics for mkdirp
mkdirp-classic
Mirror of mkdirp 0.5.2
mkdirp-infer-owner
mkdirp, but chown to the owner of the containing folder if possible and necessary
fs-mkdirp-stream
Ensure directories exist before writing to them.
@types/mkdirp
Stub TypeScript definitions entry for mkdirp, which provides its own types definitions
Recursively mkdir, like `mkdir -p`, but in node.js
npm install mkdirp
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
TypeScript (75.33%)
JavaScript (24.27%)
Shell (0.4%)
Total Downloads
18,095,780,688
Last Day
5,756,130
Last Week
94,810,491
Last Month
402,434,114
Last Year
4,229,467,311
NOASSERTION License
194 Stars
148 Commits
40 Forks
3 Watchers
2 Branches
1 Contributors
Updated on May 11, 2025
Minified
Minified + Gzipped
Latest Version
3.0.1
Package Id
mkdirp@3.0.1
Unpacked Size
104.16 kB
Size
17.83 kB
File Count
65
NPM Version
9.6.4
Node Version
18.14.0
Published on
Apr 24, 2023
Cumulative downloads
Total Downloads
Last Day
0.8%
5,756,130
Compared to previous day
Last Week
-5.7%
94,810,491
Compared to previous week
Last Month
4.4%
402,434,114
Compared to previous month
Last Year
13.8%
4,229,467,311
Compared to previous year
Like mkdir -p
, but in Node.js!
Now with a modern API and no* bugs!
* may contain some bugs
1// hybrid module, import or require() both work 2import { mkdirp } from 'mkdirp' 3// or: 4const { mkdirp } = require('mkdirp') 5 6// return value is a Promise resolving to the first directory created 7mkdirp('/tmp/foo/bar/baz').then(made => 8 console.log(`made directories, starting with ${made}`) 9)
Output (where /tmp/foo
already exists)
made directories, starting with /tmp/foo/bar
Or, if you don't have time to wait around for promises:
1import { mkdirp } from 'mkdirp' 2 3// return value is the first directory created 4const made = mkdirp.sync('/tmp/foo/bar/baz') 5console.log(`made directories, starting with ${made}`)
And now /tmp/foo/bar/baz exists, huzzah!
1import { mkdirp } from 'mkdirp'
mkdirp(dir: string, opts?: MkdirpOptions) => Promise<string | undefined>
Create a new directory and any necessary subdirectories at dir
with octal permission string opts.mode
. If opts
is a string
or number, it will be treated as the opts.mode
.
If opts.mode
isn't specified, it defaults to 0o777
.
Promise resolves to first directory made
that had to be
created, or undefined
if everything already exists. Promise
rejects if any errors are encountered. Note that, in the case of
promise rejection, some directories may have been created, as
recursive directory creation is not an atomic operation.
You can optionally pass in an alternate fs
implementation by
passing in opts.fs
. Your implementation should have
opts.fs.mkdir(path, opts, cb)
and opts.fs.stat(path, cb)
.
You can also override just one or the other of mkdir
and stat
by passing in opts.stat
or opts.mkdir
, or providing an fs
option that only overrides one of these.
mkdirp.sync(dir: string, opts: MkdirpOptions) => string|undefined
Synchronously create a new directory and any necessary
subdirectories at dir
with octal permission string opts.mode
.
If opts
is a string or number, it will be treated as the
opts.mode
.
If opts.mode
isn't specified, it defaults to 0o777
.
Returns the first directory that had to be created, or undefined if everything already exists.
You can optionally pass in an alternate fs
implementation by
passing in opts.fs
. Your implementation should have
opts.fs.mkdirSync(path, mode)
and opts.fs.statSync(path)
.
You can also override just one or the other of mkdirSync
and
statSync
by passing in opts.statSync
or opts.mkdirSync
, or
providing an fs
option that only overrides one of these.
mkdirp.manual
, mkdirp.manualSync
Use the manual implementation (not the native one). This is the default when the native implementation is not available or the stat/mkdir implementation is overridden.
mkdirp.native
, mkdirp.nativeSync
Use the native implementation (not the manual one). This is the default when the native implementation is available and stat/mkdir are not overridden.
On Node.js v10.12.0 and above, use the native fs.mkdir(p, {recursive:true})
option, unless fs.mkdir
/fs.mkdirSync
has
been overridden by an option.
made
.fs.mkdir(path, { recursive: true })
(or fs.mkdirSync
)made
.fs.mkdir
implementation, with recursive: false
made
mkdir
errormade
mkdir
errorundefined
if a root dir, or made
if set, or path
On Windows file systems, attempts to create a root directory (ie,
a drive letter or root UNC path) will fail. If the root
directory exists, then it will fail with EPERM
. If the root
directory does not exist, then it will fail with ENOENT
.
On posix file systems, attempts to create a root directory (in
recursive mode) will succeed silently, as it is treated like just
another directory that already exists. (In non-recursive mode,
of course, it fails with EEXIST
.)
In order to preserve this system-specific behavior (and because
it's not as if we can create the parent of a root directory
anyway), attempts to create a root directory are passed directly
to the fs
implementation, and any errors encountered are not
handled.
The native implementation (as of at least Node.js v13.4.0) does not provide appropriate errors in some cases (see nodejs/node#31481 and nodejs/node#28015).
In order to work around this issue, the native implementation
will fall back to the manual implementation if an ENOENT
error
is encountered.
There are a few to choose from! Use the one that suits your needs best :D
fs.mkdir(path, {recursive: true}, cb)
if:ENOENT
as the error when some other
problem is the actual cause.fs
methods in use.ENOENT
to achieve this.fs
methods in use.make-dir
if:stat
calls when using the native implementation for
this reason).ENOENT
errors for
failures that are actually related to something other than a
missing file system entry.fs
methods in use.fs
methods in use.Promise
language primitive. (Please don't.
You deserve better.)This package also ships with a mkdirp
command.
$ mkdirp -h
usage: mkdirp [DIR1,DIR2..] {OPTIONS}
Create each supplied directory including any necessary parent directories
that don't yet exist.
If the directory already exists, do nothing.
OPTIONS are:
-m<mode> If a directory needs to be created, set the mode as an octal
--mode=<mode> permission string.
-v --version Print the mkdirp version number
-h --help Print this helpful banner
-p --print Print the first directories created for each path provided
--manual Use manual implementation, even if native is available
With npm do:
npm install mkdirp
to get the library locally, or
npm install -g mkdirp
to get the command everywhere, or
npx mkdirp ...
to run the command without installing it globally.
This module works on node v8, but only v10 and above are officially supported, as Node v8 reached its LTS end of life 2020-01-01, which is in the past, as of this writing.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
8 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More