Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (36 sloc) 1.8 KB

wrench.js - Recursive file operations in Node.js

While I love Node.js, I've found myself missing some functions. Things like recursively deleting/chmodding a directory (or even deep copying a directory), or even a basic line reader, shouldn't need to be re-invented time and time again.

That said, here's my attempt at a re-usable solution, at least until something more formalized gets integrated into Node.js (hint hint). wrench.js is fairly simple to use - check out the documentation/examples below:


npm install wrench


var wrench = require('wrench'),
    util = require('util');

// Recursively create directories, sub-trees and all.
wrench.mkdirSyncRecursive(dir, 0777);

// Recursively delete the entire sub-tree of a directory, then kill the directory
wrench.rmdirSyncRecursive('my_directory_name', failSilently);

// Recursively read directories contents.

// Recursively chmod the entire sub-tree of a directory
wrench.chmodSyncRecursive('my_directory_name', 0755);

// Recursively chown the entire sub-tree of a directory
wrench.chownSyncRecursive("directory", uid, gid);

// Deep-copy an existing directory
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up');

// Read lines in from a file until you hit the end
var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) {

It should be noted that these are all currently synchronous operations.

Questions, comments? Hit me up. (ryan [at] |

Jump to Line
Something went wrong with that request. Please try again.