You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.0 KiB

4 years ago
  1. # mkdirp
  2. Like `mkdir -p`, but in node.js!
  3. [![build status](https://secure.travis-ci.org/substack/node-mkdirp.png)](http://travis-ci.org/substack/node-mkdirp)
  4. # example
  5. ## pow.js
  6. ```js
  7. var mkdirp = require('mkdirp');
  8. mkdirp('/tmp/foo/bar/baz', function (err) {
  9. if (err) console.error(err)
  10. else console.log('pow!')
  11. });
  12. ```
  13. Output
  14. ```
  15. pow!
  16. ```
  17. And now /tmp/foo/bar/baz exists, huzzah!
  18. # methods
  19. ```js
  20. var mkdirp = require('mkdirp');
  21. ```
  22. ## mkdirp(dir, opts, cb)
  23. Create a new directory and any necessary subdirectories at `dir` with octal
  24. permission string `opts.mode`. If `opts` is a non-object, it will be treated as
  25. the `opts.mode`.
  26. If `opts.mode` isn't specified, it defaults to `0777 & (~process.umask())`.
  27. `cb(err, made)` fires with the error or the first directory `made`
  28. that had to be created, if any.
  29. You can optionally pass in an alternate `fs` implementation by passing in
  30. `opts.fs`. Your implementation should have `opts.fs.mkdir(path, mode, cb)` and
  31. `opts.fs.stat(path, cb)`.
  32. ## mkdirp.sync(dir, opts)
  33. Synchronously create a new directory and any necessary subdirectories at `dir`
  34. with octal permission string `opts.mode`. If `opts` is a non-object, it will be
  35. treated as the `opts.mode`.
  36. If `opts.mode` isn't specified, it defaults to `0777 & (~process.umask())`.
  37. Returns the first directory that had to be created, if any.
  38. You can optionally pass in an alternate `fs` implementation by passing in
  39. `opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)` and
  40. `opts.fs.statSync(path)`.
  41. # usage
  42. This package also ships with a `mkdirp` command.
  43. ```
  44. usage: mkdirp [DIR1,DIR2..] {OPTIONS}
  45. Create each supplied directory including any necessary parent directories that
  46. don't yet exist.
  47. If the directory already exists, do nothing.
  48. OPTIONS are:
  49. -m, --mode If a directory needs to be created, set the mode as an octal
  50. permission string.
  51. ```
  52. # install
  53. With [npm](http://npmjs.org) do:
  54. ```
  55. npm install mkdirp
  56. ```
  57. to get the library, or
  58. ```
  59. npm install -g mkdirp
  60. ```
  61. to get the command.
  62. # license
  63. MIT