Tutorial: Extending with modules

Extending with modules

dropbox-backup may use other injected modules other than the custom archiving script, as reusable components to multiple installations

./customProcessor.js


    var CustomProcessor = function() { }
    
    CustomProcessor.prototype.process = function (context, archive, cb) {
      try {
        x.file('extra.txt', { name: 'extra.txt' });
        cb()
      } catch(err) {
        cb(err)
      }
    }

    module.exports = CustomProcessor
      

Injecting the module


    var DropboxBackup = require('dropbox-backup');
    var CustomProcessor = require('./customProcessor.js');
    
    var backup = new DropboxBackup({
        key: "DROPBOXKEY",
        secret: "DROPBOXSECRET",
        token: "DROPBOXTOKEN"
    });

    backup.use(new CustomProcessor())
    
    backup.run('filename', function (x) {
        ...
    });