Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including fs-mkdirp-stream with all npm packages installed. Try it out:

var fsMkdirpStream = require("fs-mkdirp-stream")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fs-mkdirp-stream v1.0.0

Ensure directories exist before writing to them.


NPM version Downloads Build Status AppVeyor Build Status Coveralls Status Gitter chat

Ensure directories exist before writing to them.


var to = require('to2');
var from = require('from2');
var mkdirpStream = require('fs-mkdirp-stream');

from.obj([{ dirname: '/path/to/my/', path: '/path/to/my/file.js' }])
  .pipe(mkdirpStream.obj(function(obj, callback) {
    // callback can take 3 arguments (err, dirname, mode)
    callback(null, obj.dirname);
  .pipe(to.obj(function(obj) {
    // This will be called once the directory exists
    // obj === { dirname: '/path/to/my/', path: '/path/to/my/file.js' }



Takes a resolver function or string and returns a through2 stream.

If the resolver is a function, it will be called once per chunk with the signature (chunk, callback). The callback(error, dirpath, mode) must be called with the dirpath to be created as the 2nd parameter or an error as the 1st parameter; optionally with a mode as the 3rd parameter.

If the resolver is a string, it will be created/ensured for each chunk (e.g. if it were deleted between chunks, it would be recreated). When using a string, a custom mode can't be used.


The same as the top-level API but for object streams. See the example to see the benefit of object streams with this module.



Contains a custom implementation of mkdirp originally based on (Licensed MIT/X11 - Copyright 2010 James Halliday) with heavy modification to better support custom modes.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free