You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

make-dir

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-dir

Make a directory and its parents if needed - Think `mkdir -p`


Version published
Maintainers
1
Created

Package description

What is make-dir?

The make-dir npm package is designed to simplify the process of creating directories along with their subdirectories in a Node.js environment. It wraps around the native fs.mkdir and fs.mkdirSync methods, providing a promise-based API and ensuring that all necessary parent directories are created if they do not exist. This is particularly useful for setting up complex directory structures with minimal code.

What are make-dir's main functionalities?

Creating a directory with promise

This feature allows for the creation of a directory and all necessary parent directories using a promise-based API. It's useful for asynchronous directory creation without blocking the main thread.

const makeDir = require('make-dir');

makeDir('path/to/dir').then(path => {
  console.log(`Directory created at ${path}`);
});

Creating a directory synchronously

This feature provides a synchronous method to create a directory and all necessary parent directories. It's useful when you need to ensure a directory is created before proceeding with the execution of subsequent code.

const makeDir = require('make-dir');

const path = makeDir.sync('path/to/dir');
console.log(`Directory created at ${path}`);

Other packages similar to make-dir

Readme

Source

make-dir

Make a directory and its parents if needed - Think mkdir -p

[!TIP] You probably want the built-in fsPromises.mkdir('…', {recursive: true}) instead.

Advantages over fsPromises.mkdir('…', {recursive: true})

  • Supports a custom fs implementation.

Advantages over mkdirp

  • Promise API (Async/await ready!)
  • Fixes many mkdirp issues: #96 #70 #66
  • CI-tested on macOS, Linux, and Windows
  • Actively maintained
  • Doesn't bundle a CLI
  • Uses the native fs.mkdir/mkdirSync recursive option in Node.js unless overridden

Install

npm install make-dir

Usage

$ pwd
/Users/sindresorhus/fun
$ tree
.
import {makeDirectory} from 'make-dir';

const path = await makeDirectory('unicorn/rainbow/cake');

console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
$ tree
.
└── unicorn
    └── rainbow
        └── cake

Multiple directories:

import {makeDirectory} from 'make-dir';

const paths = await Promise.all([
	makeDirectory('unicorn/rainbow'),
	makeDirectory('foo/bar')
]);

console.log(paths);
/*
[
	'/Users/sindresorhus/fun/unicorn/rainbow',
	'/Users/sindresorhus/fun/foo/bar'
]
*/

API

makeDirectory(path, options?)

Returns a Promise for the path to the created directory.

makeDirectorySync(path, options?)

Returns the path to the created directory.

path

Type: string

The directory to create.

options

Type: object

mode

Type: integer
Default: 0o777

The directory permissions.

fs

Type: object
Default: import fs from 'node:fs'

Use a custom fs implementation. For example graceful-fs.

Using a custom fs implementation will block the use of the native recursive option if fs.mkdir or fs.mkdirSync is not the native function.

Keywords

FAQs

Package last updated on 02 May 2024

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc