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
Installation
With npm do:
$ npm install filerake
Tests
Use 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, 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 : emptycollname
- 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 *
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
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.
var fr = new Filerake(__dirname);
fr.sync(function(err, collection) {
console.log('Synchronistion done !');
}
)