Bruno Pedro

Recursive directory creation with nodejs

I’m doing some code in nodejs and I found the need to create directories recursively. Basically I need to have the same functionality offered by mkdir -p.

The fs lib doesn’t offer this functionality so I looked around but couldn’t really find anything that suited me. I finally gave up and I’m writing the function myself.

Here’s the code:

Update: I just converted this code into an extension to the original fs lib so that it’s easier to use. The extended lib is called node-fs and is available on GitHub.