jprichardson/node-fs-extra — pull request #22 by jric (2013-03-29 21:58:04+00:00)
Title: Add a limit option to mkdirs()

This is a backward-compatible extension that pulls in no extra dependencies. It makes use of mkdirs() safer, by allowing the developer to specify how many levels of hierarchy are allowed to be created by mkdirs(). Because mkdirs() will happily create whatever you tell it to, sometimes you don't find the error in your logic right away and you end up creating directories in unintended places.

Another benefit of this extension is that it gives you the semantics of "ensureDirectory()" from some other fs extensions. The idea behind this is that you want to create a directory if it doesn't already exist, but you don't want an error if it does already exist. In this case, you don't want a hierarchy of directories created, just a single directory, and it would be a legitimate error if the parent directory did not exist. You can do this with the base fs functions, but it gets a little ugly and requires seven lines of code where you only need one.