Home Reference Source Repository


A module for interacting with Back Blaze B2Cloud


In ~/.b2cloud.json place your credentials

i.e. { "accountId": "", "applicationKey": "" }


Please note this is being actively worked on and will soon support all API operations as listed here:


I also will be adding helpers methods such as uploadFile, getBucketByName to make it easier to use


All methods can use promises or callbacks


npm install b2cloud

Setup a file .b2cloud in your home folder. Setup like this:,

        "accountId": "",
        "applicationKey": ""


var b2cloud = require('b2cloud');
b2cloud.getBasicAuth().then(function(auth) {
// authorized

Please note that getBasicAuth caches the auth token for 2 hours, or until your process closes.


function createBucket(name, type)

   * Creates a bucket in the b2cloud
   * @param {string} name - Name of the bucket
   * @param {string} type - Either allPublic or allPrivate, sets the bucket to public or private access.
   * @param {function} [callback] - The optional callback
   * @returns If no callback provided, retunrs a {Promise} that resolves to the bucket object.
   * Otherwise returns the bucket {object}.
b2cloud.createBucket(name, type, callback)

function listBuckets()

   * Lists all buckets you have created.
   * @param {function} [callback] - The optional callback.
   * @return If no callback is provided, returns a {Promise} that resolves to an {array} of bucket {objects}.
   * Otherwise returns the {array} of bucket {objects}.

function getBucketByName(name)

   * Helper function that returns a bucket object by its name.
   * @param {string} name - The name of the bucket.
   * @param {function} [callback] - An optional callback
   * @return A promise that resolves with the bucket object if found, otherwise rejects.
   getBucketByName(name, callback)

function listBucketFiles(name)

   * Lists all files inside of a bucket.
   * @param {string} name - The name of the bucket
   * @param {string} [startFileName] - If the number of files exceeds the response limit, this will set
   * which file to start listing from
   * @param {number} [maxFileCount] - Max number of files to return, cannot be greater than 1000
   * @see https://www.backblaze.com/b2/docs/b2_list_file_names.html
   * @param {function} [callback] - The optional callback
  listBucketFiles(name, startFileName, maxFileCount, callback)



   * Gets the uploadUrl for uploadinga file to b2cloud
   * @param {string} bucketName - Name of the bucket to get a uploadUrl for
   * @param {function} [callback] - Optional callback
  getUploadUrl(bucketName, callback) {

uploadFile(filePath, bucketName)

   * Helper function that automatically generates the uploadUrl, hashes the file and
   * uploads it to b2cloud.
   * @param {string} filePath - The file path to the file you want to upload
   * @param {string} bucketName - The bucke to upload the file to.
   * @param {function} [callback] - The optional callback

downloadFile(name, bucketName, savePath, range)

   * Downloads a file from b2cloud
   * @param {string} name - Name of the file to download
   * @param {string} bucketName - Bucket the file resides in
   * @param {string} savePath - Path to save the file to
   * @param {object} range - The range object used to fetch only a byte range, byte range is inclusive
   * @param {number} range.start - The start byte to download
   * @param {number} range.end - The end byte to download
   * @see https://www.backblaze.com/b2/docs/b2_download_file_by_name.html
   * @param {function} [callback] - The optional callback
downloadFile(name, bucketName, savePath, range, callback)