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:
Installation
npm install wrench
Usage
var wrench = require('wrench'),
util = require('util');
Synchronous operations
wrench.mkdirSyncRecursive(dir, 0777);
wrench.rmdirSyncRecursive('my_directory_name', failSilently);
wrench.readdirSyncRecursive('my_directory_name');
wrench.chmodSyncRecursive('my_directory_name', 0755);
wrench.chownSyncRecursive("directory", uid, gid);
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
forceDelete: bool,
excludeHiddenUnix: bool,
preserveFiles: bool,
inflateSymlinks: bool,
filter: regexp,
whitelist: bool,
});
var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) {
util.puts(f.getNextLine());
}
Asynchronous operations
var files = [];
wrench.readdirRecursive('my_directory_name', function(error, curFiles) {
});
wrench.copyDirRecursive(srcDir, newDir, {forceDelete: bool }, callbackfn);
Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)