1 |
3a515b92
|
cagy
|
# make-dir [](https://travis-ci.org/sindresorhus/make-dir) [](https://ci.appveyor.com/project/sindresorhus/make-dir/branch/master) [](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
|
33 |
|
|
const makeDir = require('make-dir');
|
34 |
|
|
|
35 |
|
|
makeDir('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 |
|
|
|
49 |
|
|
Multiple directories:
|
50 |
|
|
|
51 |
|
|
```js
|
52 |
|
|
const makeDir = require('make-dir');
|
53 |
|
|
|
54 |
|
|
Promise.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 |
|
|
|
73 |
|
|
Returns a `Promise` for the path to the created directory.
|
74 |
|
|
|
75 |
|
|
### makeDir.sync(path, [options])
|
76 |
|
|
|
77 |
|
|
Returns the path to the created directory.
|
78 |
|
|
|
79 |
|
|
#### path
|
80 |
|
|
|
81 |
|
|
Type: `string`
|
82 |
|
|
|
83 |
|
|
Directory to create.
|
84 |
|
|
|
85 |
|
|
#### options
|
86 |
|
|
|
87 |
|
|
Type: `Object`
|
88 |
|
|
|
89 |
|
|
##### mode
|
90 |
|
|
|
91 |
|
|
Type: `integer`<br>
|
92 |
|
|
Default: `0o777 & (~process.umask())`
|
93 |
|
|
|
94 |
|
|
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
|
95 |
|
|
|
96 |
|
|
##### fs
|
97 |
|
|
|
98 |
|
|
Type: `Object`<br>
|
99 |
|
|
Default: `require('fs')`
|
100 |
|
|
|
101 |
|
|
Use 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 |
|
|
|
116 |
|
|
MIT © [Sindre Sorhus](https://sindresorhus.com)
|