UNPKG

castor-load

Version:

Traverse a directory to build a MongoDB collection with the found files. Then it's enable to keep directory and collection synchronised.

75 lines (51 loc) 2.34 kB
# FileRake for NodeJS/Javascript Traverse a directory to build a MongoDB collection with the found files. Then it's enable to keep directory and collection synchronised. ## Contributors * [Nicolas Thouvenin](https://github.com/touv) # Installation With [npm](http://npmjs.org) do: $ npm install filerake # Tests Use [mocha](https://github.com/visionmedia/mocha) to run the tests. $ npm install mocha $ mocha test # API Documentation ## Constructor Filerake(String directory, [Object options]) Create an new object to synchronise **directory** with MongoDB collection ###Options * `mongo.url` - *string* - URL to connect to MongoDB (see [documentation](http://docs.mongodb.org/manual/reference/connection-string/), if not specified, it can look up the environment variable "MONGO URL" ; *default : 'mongodb://localhost:27017/test/'* * `ignore` - *array* - List of files to ignore (Regex accepted) : *default : empty* * `collname` - *string* - MongoDB collection name : *default : automatic * * `persitent` - *boolean* - Keep synchronization after a complete analysis : *default : true * * `concurrency` - *number* - Determine how many statement should be run in parallel : *default : 1 * * `maxFileSize` - *string* - Limits the size of each file in the directory : *default : 128mb * * `delay` - *number* - Delay file processing when the stack is full (milliseconds) : *default : 30000 * ```javascript var options = { "mongo" : { "url" : "mongodb://localhost:27017/test/" }, "ignore" : [ "**/.*", "*~", "*.sw?", "*.old", "*.bak", "**/node_modules"] }; var fr = new Filerake(__dirname, options); ``` ## use (Function callback) Use **callback** to add/remove some information on each file found ```javascript var fr = new Filerake(__dirname); fr.use(function (doc, next) { doc.name = doc.basename.toUpperCase(); next(); }; } ``` ## sync (Function callback) start synchronization between the directory and the MongoDB collection. **callback** will be called after a complete analysis. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain an handle to the MongoDb collection. ```javascript var fr = new Filerake(__dirname); fr.sync(function(err, collection) { console.log('Synchronistion done !'); } ) ```