Socket
Socket
Sign inDemoInstall

mkdirp

Package Overview
Dependencies
0
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mkdirp

Recursively mkdir, like `mkdir -p`


Version published
Maintainers
1
Weekly downloads
71,049,748
decreased by-9.51%

Weekly downloads

Package description

What is mkdirp?

The mkdirp npm package is a utility module that allows you to create directories and all necessary subdirectories in a single command, similar to the 'mkdir -p' command in UNIX systems. It is useful for ensuring that a given directory path exists without manually checking and creating each level of the directory structure.

What are mkdirp's main functionalities?

Create a directory with subdirectories

This feature allows you to create a directory and any necessary parent directories. The function returns a promise that resolves to the first directory that had to be created, or null if all directories already existed.

const mkdirp = require('mkdirp');

mkdirp('/tmp/some/long/path').then(made => console.log(`Made directories: ${made}`));

Use with async/await

This feature demonstrates how mkdirp can be used with async/await syntax for cleaner, more readable asynchronous code.

const mkdirp = require('mkdirp');

(async () => {
  try {
    const made = await mkdirp('/tmp/some/long/path');
    console.log(`Made directories: ${made}`);
  } catch (e) {
    console.error(e);
  }
})();

Custom file mode (permissions)

This feature allows you to specify the file mode (permissions) when creating directories. The mode can be set so that the created directories have the desired permissions.

const mkdirp = require('mkdirp');

mkdirp('/tmp/some/long/path', { mode: 0o775 }).then(made => console.log(`Made directories with mode: ${made}`));

Other packages similar to mkdirp

Readme

Source

mkdirp

Like mkdir -p, but in node.js!

build status

example

pow.js

var mkdirp = require('mkdirp');
    
mkdirp('/tmp/foo/bar/baz', function (err) {
    if (err) console.error(err)
    else console.log('pow!')
});

Output

pow!

And now /tmp/foo/bar/baz exists, huzzah!

methods

var mkdirp = require('mkdirp');

mkdirp(dir, mode, cb)

Create a new directory and any necessary subdirectories at dir with octal permission string mode.

If mode isn't specified, it defaults to 0777 & (~process.umask()).

cb(err, made) fires with the error or the first directory made that had to be created, if any.

mkdirp.sync(dir, mode)

Synchronously create a new directory and any necessary subdirectories at dir with octal permission string mode.

If mode isn't specified, it defaults to 0777 & (~process.umask()).

Returns the first directory that had to be created, if any.

install

With npm do:

npm install mkdirp

license

MIT

Keywords

FAQs

Last updated on 22 Feb 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc