60637cf8b18ee3f675337bd2bcc8836c67e81df0d3cf80c89ec9e811d4b43dbd4608c897814763bacede103f7a291806667dd0574e2e12eae20530fe295652 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. > Make a directory and its parents if needed - Think `mkdir -p`
  3. ## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)
  4. - Promise API *(Async/await ready!)*
  5. - 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)
  6. - 100% test coverage
  7. - CI-tested on macOS, Linux, and Windows
  8. - Actively maintained
  9. - Doesn't bundle a CLI
  10. ## Install
  11. ```
  12. $ npm install make-dir
  13. ```
  14. ## Usage
  15. ```
  16. $ pwd
  17. /Users/sindresorhus/fun
  18. $ tree
  19. .
  20. ```
  21. ```js
  22. const makeDir = require('make-dir');
  23. makeDir('unicorn/rainbow/cake').then(path => {
  24. console.log(path);
  25. //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
  26. });
  27. ```
  28. ```
  29. $ tree
  30. .
  31. └── unicorn
  32. └── rainbow
  33. └── cake
  34. ```
  35. Multiple directories:
  36. ```js
  37. const makeDir = require('make-dir');
  38. Promise.all([
  39. makeDir('unicorn/rainbow')
  40. makeDir('foo/bar')
  41. ]).then(paths => {
  42. console.log(paths);
  43. /*
  44. [
  45. '/Users/sindresorhus/fun/unicorn/rainbow',
  46. '/Users/sindresorhus/fun/foo/bar'
  47. ]
  48. */
  49. });
  50. ```
  51. ## API
  52. ### makeDir(path, [options])
  53. Returns a `Promise` for the path to the created directory.
  54. ### makeDir.sync(path, [options])
  55. Returns the path to the created directory.
  56. #### path
  57. Type: `string`
  58. Directory to create.
  59. #### options
  60. Type: `Object`
  61. ##### mode
  62. Type: `integer`<br>
  63. Default: `0o777 & (~process.umask())`
  64. Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
  65. ##### fs
  66. Type: `Object`<br>
  67. Default: `require('fs')`
  68. Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
  69. ## Related
  70. - [make-dir-cli](https://github.com/sindresorhus/make-dir-cli) - CLI for this module
  71. - [del](https://github.com/sindresorhus/del) - Delete files and directories
  72. - [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching
  73. - [cpy](https://github.com/sindresorhus/cpy) - Copy files
  74. - [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
  75. - [move-file](https://github.com/sindresorhus/move-file) - Move a file
  76. ## License
  77. MIT © [Sindre Sorhus](https://sindresorhus.com)