1.2.1 • Public • Published


Build Status Dependencies Downloads

digitalocean-node is a library for nodejs to access the DigitalOcean v2 API.


npm install digitalocean --save


Every resource is accessed via an instance of the client. Please chose one of your tokens and use that where ever TOKEN is referenced. For example:

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN'); // See

Every resource method accepts an optional callback as the last argument. For example:

client.account.get(function(err, account) {
  console.log(err); // null on success
  console.log(account); //

See below for more options in the callback.

Resource methods also return a promise. For example:

client.droplets.list().then(function(droplets) {
  var droplet = droplets[0];
  return client.droplets.snapshot(;
}).then(function() {
  console.log("created a snapshot of a Droplet!");
}).catch(function(err) {
  // Deal with an error

All resources and actions are listed below, however, the general structure of the client follows the following pattern:

client.droplets.create(options, callback);
client.droplets.get(123, callback);
client.droplets.delete(123, callback);
client.droplets.powerOff(123, callback);
client.droplets.getAction(123, 456, callback);

Spaces support

DigitalOcean's Spaces is an S3-compatible object storage service. The API for spaces is a different schema at a different abstraction level (XML and actual file objects) than the normal "control" API. The good news is that it's interopable with lots of existing S3 clients, this is a node one.

You should be able to use Spaces similarly to:

var s3 = require('s3');
var client = s3.createClient({
  s3Options: {
    accessKeyId: "your spaces key from",
    secretAccessKey: "your spaces secret from",
    region: "nyc3",
    endpoint: '',

Client Options

The DigitalOcean client depends on request, and options can be passed through (e.g. a proxy or user agent). For example:

var client = digitalocean.client('TOKEN', {
  request: myInitializedRequestObject,
  requestOptions: {
    proxy: '',
    headers: {
      'User-Agent': 'foo'

Other options include:

var client = digitalocean.client('TOKEN', {
  promise: MySpecialPromiseVersion, // defaults to Promise
  decamelizeKeys: false // defaults to true

Using a client with an access token

var client = digitalocean.client('TOKEN');
client.get('/account', {}, 200, 'account', function (err, status, body, headers) {
  console.log(body); //json object

Callback function signature

All callbacks will be passed:

  1. an error (null if no error occurred)
  2. a resource object
  3. the response headers
  4. the raw response body

For example:

client.account.get(function(err, account, headers, response) {
  console.log("error: " + err);
  console.log("account: " + account);
  console.log("headers: " + headers);
  console.log("response: " + response);

Promise result

Promise results are the resource(s) returned by a successful response - a list response object, an individual object, or a blank object (for successful empty responses such as deletes). These objects have a special property, _digitalOcean that includes response information. For example:

// ...
.then(function(object) {
  console.log(object); // =>
  // {
  //   _digitalOcean: {
  //     statusCode: 204,
  //     body: {},
  //     headers: {}
  //   }
  // }


Auto pagination

Although the DigitalOcean API returns results from query endpoints in pages, this client abstracts that notion by lazily fetching subsequent pages when they are needed. This allows developers to easily handles fetching large lists of resources without having to manually paginate results and perform subsequent requests - adding a layer of convenience on top of what is a common limitation in REST based APIs. An example of using this is:

client.droplets.list(function(err, droplets) {
  if (err) {
    return console.error('Error fetching pages', err);
  droplets.all(function(err, droplet) {
    console.log(err, droplet);
  var error = iterator.error()
  if (error) {

Note that the magic .length property on ListResponse is tied to the first page of results.

client.droplets.list(function(err, droplets) {
  if (err) {
    return console.error('Error fetching pages', err);
  // Limited to original page only:
  for (var i = 0, len = droplets.length; i < len; i++) {

Under the hood, this enumeration is handled by an iterator object, this can be accessed as well (it uses promises internally):

client.droplets.list(function(err, droplets) {
  if (err) {
    return console.error('Error fetching pages', err);
  var iterator = droplets.iterator();
  var iterable =;
  while(!iterable.done) {
    iterable.value.then(function(value) {
      iterable =;
  // Check the error afterwards:
  var error = iterator.error()
  if (error) {

Pagination parameters

If a function declares pagination parameters, then results from the function are arranged in pages. These arguments are:

The page argument is optional and is used to specify which page of objects to retrieve. The perPage argument is also optional and is used to specify how many objects per page.

// Normal usage of function
client.droplets.list(callback); // Callback receives an array of first 25 issues
// Using pagination parameters
client.droplets.list(2, 100, callback); // Callback receives an array of second 100 issues
client.droplets.list(10, callback); // Callback receives an array of 25 issues from page 10
// Pagination parameters can be set with query object too
  page: 2,
  per_page: 100
}, callback); //array of second 100 issues which are closed

Pagination examples

To fetch all the pages of a resource, the pages must be traversed. For example, to fetch all Droplets:

getAllDroplets(function(allDroplets) {
function getAllDroplets(callback, page, array) {
  client.droplets.list(page, function(err, droplets, _, response) {
    if (err) {
      return console.error('Error fetching pages', err);
    if (page == null) {
      page = 1;
    if (array == null) {
      array = [];
    array = array.concat(droplets);
    // has no pages or has pages and has no last page
    var isLastPage = response['links'] && (
      !response['links']['pages'] ||
        (response['links']['pages'] && response['links']['pages']['last'] === undefined)
    if (!err && isLastPage) {, array);
    } else if (!err && !isLastPage) {
      getAllDroplets(callback, page + 1, array);
    } else {
      // whoops, try again
      getAllDroplets(callback, page, array);

Or Promise style:

getAllDroplets().then(function(allDroplets) {
}).catch(function(err) {
function getAllDroplets() {
  var allDroplets = [];
  function getDropletPage(page) {
    if (page == null) {
      page = 1;
    return client.droplets.list(page)
      .each(function(droplet) {
      .then(function(droplets) {
        var links = droplets._digitalocean.body.links;
        var isLastPage = links && (
          !links.pages ||
            (links.pages && links.pages.last === undefined)
        if (isLastPage) {
          return allDroplets;
        } else {
          return getDropletPage(page + 1);
  return getDropletPage();

Rate Limiting

You can also check your rate limit status by calling the following.

client.droplets.list(function (err, account, headers, response) {
  console.log(headers['ratelimit-remaining']); // 4999
  console.log(headers['ratelimit-limit']);  // 5000
  console.log(headers['ratelimit-reset']);  // Time in Unix Epoch, e.g. 1415984218

Usage in the Browser

This library is also available as a single file built for usage in the browser at dist/digitalocean.js. It uses browserify to package all dependencies and output the built file. This file is updated and released to Bower for each release with the same version.

For example, using the built file at dist/digitalocean.js:

    <script src="dist/digitalocean.js"></script> 
      var client = digitalocean.client('TOKEN');
      client.account.get(function(_, account) {

All Resources and Actions

The following resources and actions correspond to the resources and actions documented on DigitalOcean's API. Some methods take an attributes argument, which is a plain JavaScript object, e.g. { email: '' }, whose keys and appropriate values are also documented in DigitalOcean's API documentation.

Account resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.account.get([callback])
  • client.account.listSshKeys([page, perPage], [callback])
  • client.account.listSshKeys([queryObject], [callback])
  • client.account.createSshKey(attributes, [callback])
  • client.account.getSshKey(, [callback])
  • client.account.deleteSshKey(, [callback])
  • client.account.updateSshKey(, attributes, [callback])

For the latest valid account attributes, see the official docs.

Action resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.actions.list([page, perPage], [callback])
  • client.actions.get([queryObject], [callback])
  • client.actions.get(, [callback])

Block Storage/Volume resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.volumes.list([page, perPage], [callback])
  • client.volumes.list([queryObject], [callback])
  • client.volumes.get(, [callback])
  • client.volumes.create(attributes, [callback])
  • client.volumes.delete(, [callback])
  • client.volumes.listActions([page, perPage], [callback])
  • client.volumes.listActions([queryObject], [callback])
  • client.volumes.getAction(,, [callback])

Methods resulting in an action:

  • client.volumes.attach(, parametersOrDropletId, [callback])
  • client.volumes.detach(, [callback])
  • client.volumes.resize(, parametersOrSizeGibabytes, region, [callback])

For the latest valid volume attributes and action parameters, see the official docs.

Certificate resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.certificates.list([page, perPage], [callback])
  • client.certificates.list([queryObject], [callback])
  • client.certificates.get(, [callback])
  • client.certificates.create(attributes, [callback])
  • client.certificates.delete(, [callback])

For the latest valid certificate attributes, see the official docs.

Domain resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  •[page, perPage,] [callback])
  •[queryObject,] [callback])
  •, [callback])
  •, [callback])
  •, [callback])
  •[page, perPage,], [callback])
  •[queryObject,], [callback])
  •, attributes, [callback])
  •,, [callback])
  •,, [callback])
  •,,, attributes, [callback])

For the latest valid domain attributes, see the official docs. For the latest valid domain record attributes, see the official docs.

Droplet resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.droplets.list([page, perPage,] [callback])
  • client.droplets.list([queryObject,] [callback])
  • client.droplets.get(, [callback])
  • client.droplets.create(attributes, [callback])
  • client.droplets.delete(, [callback])
  • client.droplets.deleteByTag(, [callback])
  • client.droplets.kernels(, [page, perPage,] [callback])
  • client.droplets.kernels(, [queryObject,] [callback])
  • client.droplets.snapshots(, [page, perPage,] [callback])
  • client.droplets.snapshots(, [queryObject,] [callback])
  • client.droplets.backups(, [page, perPage,] [callback])
  • client.droplets.backups(, [queryObject,] [callback])
  • client.droplets.neighbors(, [page, perPage,] [callback])
  • client.droplets.neighbors(, [queryObject,] [callback])
  • client.droplets.listActions(, [page, perPage,] [callback])
  • client.droplets.listActions(, [queryObject,] [callback])
  • client.droplets.getAction(,, [callback])

Methods resulting in an action:

  • client.droplets.actionByTag(, actionType, [callback])
  • client.droplets.reboot(, [callback])
  • client.droplets.powerCycle(, [callback])
  • client.droplets.shutdown(, [callback])
  • client.droplets.powerOff(, [callback])
  • client.droplets.powerOn(, [callback])
  • client.droplets.passwordReset(, [callback])
  • client.droplets.enableIpv6(, [callback])
  • client.droplets.enableBackups(, [callback])
  • client.droplets.disableBackups(, [callback])
  • client.droplets.enablePrivateNetworking(, [callback])
  • client.droplets.snapshot(, parametersOrName, [callback])
  • client.droplets.changeKernel(, parametersOrKernelId, [callback])
  • client.droplets.rename(, parametersOrHostname, [callback])
  • client.droplets.rebuild(, parametersOrImage, [callback])
  • client.droplets.restore(, parametersOrImageId, [callback])
  • client.droplets.resize(, parametersOrSizeSlug, [callback])

For the latest valid droplet attributes, see the official docs. For the latest valid droplet action parameters, see the official docs.

Floating IP resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.floatingIps.list([page, perPage], [callback])
  • client.floatingIps.list([queryObject], [callback])
  • client.floatingIps.get(floatingIp.ip, [callback])
  • client.floatingIps.create(attributes, [callback])
  • client.floatingIps.delete(floatingIp.ip, [callback])
  • client.floatingIps.listActions(floatingIp.ip, [page, perPage], [callback])
  • client.floatingIps.listActions(floatingIp.ip, [queryObject], [callback])
  • client.floatingIps.getAction(floatingIp.ip,, [callback])

Methods resulting in an action:

  • client.floatingIps.assign(floatingIp.ip, parametersOrDropletId, [callback])
  • client.floatingIps.unassign(floatingIp.ip, [callback])

For the latest valid attributes, see the official docs.

Firewall resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.firewalls.list([page, perPage], [callback])
  • client.firewalls.list([queryObject], [callback])
  • client.firewalls.get(, [callback])
  • client.firewalls.create(attributes, [callback])
  • client.firewalls.delete(, [callback])
  • client.firewalls.update(, attributes, [callback])
  • client.firewalls.addDroplets(, dropletIds, [callback])
  • client.firewalls.removeDroplets(, dropletIds, [callback])
  • client.firewalls.addTags(, tags, [callback])
  • client.firewalls.removeTags(, tags, [callback])
  • client.firewalls.addRules(, rules, [callback])
  • client.firewalls.removeRules(, rules, [callback])

Image resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.images.list([page, perPage], [callback])
  • client.images.list([queryObject], [callback])
  • client.images.get(, [callback])
  • client.images.delete(, [callback])
  • client.images.update(, attributes, [callback])
  • client.images.listActions(, [page, perPage], [callback])
  • client.images.listActions(, [queryObject], [callback])
  • client.images.getAction(,, [callback])

Methods resulting in an action:

  • client.images.transfer(, parametersOrRegionSlug, [callback])
  • client.images.convert(, [callback])

For the latest valid attributes, see the official docs.

Load Balancer resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.loadBalancers.list([page, perPage], [callback])
  • client.loadBalancers.list([queryObject], [callback])
  • client.loadBalancers.get(, [callback])
  • client.loadBalancers.update(, attributes, [callback])
  • client.loadBalancers.delete(, [callback])
  • client.loadBalancers.add(, parametersOrIds, [callback])
  • client.loadBalancers.remove(, parametersOrIds, [callback])
  • client.loadBalancers.createForwardingRules(, parametersOrRules, [callback])
  • client.loadBalancers.deleteForwardingRules(, parametersOrRules, [callback])

For the latest valid attributes and parameters, see the official docs.

Region resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.regions.list([page, perPage], [callback])
  • client.regions.list([queryObject], [callback])

Size resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.sizes.list([page, perPage], [callback])
  • client.sizes.list([queryObject], [callback])

Snapshot resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.snapshots.list([page, perPage], [callback])
  • client.snapshots.list([queryObject], [callback])
  • client.snapshots.get(, [callback])
  • client.snapshots.delete(, [callback])

Tag resource

var digitalocean = require('digitalocean');
var client = digitalocean.client('TOKEN');
  • client.tags.list([page, perPage], [callback])
  • client.tags.list([queryObject], [callback])
  • client.tags.get(, [callback])
  • client.tags.create(attributes, [callback])
  • client.tags.update(, attributes, [callback])
  • client.tags.tag(, [resources], [callback])
  • client.tags.untag(, [resources], [callback])
  • client.tags.delete(, [callback])

For the latest valid attributes, see the official docs.


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


npm test



npm run release:patch # or release:minor or release:major depending on the type of version bump 




Based on the work of @pksunkara in octonode.

Package Sidebar


Weekly Downloads






Unpacked Size

4.15 MB

Total Files


Last publish


  • phillbaker