GridFS that is easy to use and mongojs compliant


A GridFS module that is easy to use and mongojs compliant. It is available through npm

npm install gridjs

It is easy to use

To get started pass a connection string or mongojs instance to the gridjs constructor

var gridjs = require('gridjs');
var fs = require('fs');
var gs = gridjs('my-connection-string');
// or using a mongojs instance 
var db = mongojs('my-connection-string');
var gs = gridjs(db);
// or using a node-mongodb-native instance 
mongodb.Db.connect(connectionString, function(errdb) {
    var gs = gridjs(db);

Writing files using gridjs is a simple as piping to gs.createWriteStream(filename) which returns a streams2 WriteStream


Alternatively if you have the entire file as a single buffer you can use gs.write(filename, buffer, [enc], callback)

gs.write('test-file', new Buffer('hello world'), function(err) {
    console.log('file is written', err);

Similary when reading files you just pipe from gs.createReadStream(filename, [options]) which returns a streams2 ReadStream


There is also a, [enc], callback) shorthand if you want to read the entire file into a buffer'test-file', function(errbuffer) {
    console.log('file is read', buffer);