Connecting to OpenStack in node.js with pkgcloud

If you’ve ever wanted to build a node.js app that worked with OpenStack, HP Helion OpenStack, or the HP Public Cloud the package to use pkgcloud. This is a multi-cloud library for node.js that includes support some of the common components of OpenStack. It’s supported enough by the OpenStack community that it’s the node.js library listed on the OpenStack developer portal.

Note, until recently there was the hpcloud-js library that I’ve now deprecated because it is superseded by pkgcloud. hpcloud-js served us well but given the support for OpenStackn in pkgcloud and the superior feature coverage we’ve decided to direct users there instead.

Creating A Client

Let’s look at an example where we create an object storage client. This client can be used to manage objects, containers, meta-data, and more.

var client = require('pkgcloud').storage.createClient({
    provider: 'openstack',
    username: 'your-user-name',
    password: 'your-password',
    tenantId: 'exampleProject',
    region: 'exampleRegion',
    authUrl: ''

If you’re connecting to the HP Public Cloud and would like to use your keys instead of a username and password the hp provider can be used.

Retrieval Example

Given the client in the previous example, we can retrieve information from the endpoint. For example, we can get a list of containers like so.

client.getContainers(function(err, containers) {
    // Containers is an array of container objects.

Examples and Documentation

There’s a bit of documentation and examples in the pkgcloud docs. If you’re looking to dive in it’s worth starting there.