• Home
Name Date Size #Lines LOC

..--

index.jsD12-May-20241.8 KiB8668

licenseD12-May-20241.1 KiB105

package.jsonD12-May-20241.9 KiB8786

readme.mdD12-May-20242.6 KiB11777

readme.md

1# make-dir [![Build Status: macOS & Linux](https://travis-ci.org/sindresorhus/make-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/make-dir) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/e0vtt8y600w91gcs/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/make-dir/branch/master) [![codecov](https://codecov.io/gh/sindresorhus/make-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/make-dir)
2
3> Make a directory and its parents if needed - Think `mkdir -p`
4
5
6## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)
7
8- Promise API *(Async/await ready!)*
9- Fixes many `mkdirp` issues: [#96](https://github.com/substack/node-mkdirp/pull/96) [#70](https://github.com/substack/node-mkdirp/issues/70) [#66](https://github.com/substack/node-mkdirp/issues/66)
10- 100% test coverage
11- CI-tested on macOS, Linux, and Windows
12- Actively maintained
13- Doesn't bundle a CLI
14
15
16## Install
17
18```
19$ npm install make-dir
20```
21
22
23## Usage
24
25```
26$ pwd
27/Users/sindresorhus/fun
28$ tree
29.
30```
31
32```js
33const makeDir = require('make-dir');
34
35makeDir('unicorn/rainbow/cake').then(path => {
36	console.log(path);
37	//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
38});
39```
40
41```
42$ tree
43.
44└── unicorn
45    └── rainbow
46        └── cake
47```
48
49Multiple directories:
50
51```js
52const makeDir = require('make-dir');
53
54Promise.all([
55	makeDir('unicorn/rainbow')
56	makeDir('foo/bar')
57]).then(paths => {
58	console.log(paths);
59	/*
60	[
61		'/Users/sindresorhus/fun/unicorn/rainbow',
62		'/Users/sindresorhus/fun/foo/bar'
63	]
64	*/
65});
66```
67
68
69## API
70
71### makeDir(path, [options])
72
73Returns a `Promise` for the path to the created directory.
74
75### makeDir.sync(path, [options])
76
77Returns the path to the created directory.
78
79#### path
80
81Type: `string`
82
83Directory to create.
84
85#### options
86
87Type: `Object`
88
89##### mode
90
91Type: `integer`<br>
92Default: `0o777 & (~process.umask())`
93
94Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
95
96##### fs
97
98Type: `Object`<br>
99Default: `require('fs')`
100
101Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
102
103
104## Related
105
106- [make-dir-cli](https://github.com/sindresorhus/make-dir-cli) - CLI for this module
107- [del](https://github.com/sindresorhus/del) - Delete files and directories
108- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching
109- [cpy](https://github.com/sindresorhus/cpy) - Copy files
110- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
111- [move-file](https://github.com/sindresorhus/move-file) - Move a file
112
113
114## License
115
116MIT © [Sindre Sorhus](https://sindresorhus.com)
117