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.


2 thoughts on “Recursive directory creation with nodejs”

  1. Looks great for Linux, but on Windows, backslashes are used for path.normalize(). It would be great to find a less hacky and a more cross-platformly way of doing this.

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s