Node.js SDK for accessing the Rackspace Open Cloud API
npm install thunderhead
Methods are called using Node.js' function(options, callback) convention. If there is only one required argument you can pass it instead of the options object.
Below is an example call logging all empty Rackspace Cloud Files containers
var thunderhead = new (require('thunderhead'))({
username : 'RackspaceUsername',
apikey : 'RackspaceKey',
region : 'ORD'
});
thunderhead.storage.listContainers({}, function(err, reply){
if(err) return console.log(err);
reply.forEach(function(container){
console.log(container);
if(container.count === 0) return console.log(container + "is empty");
});
});
You can also pipe the results through a stream if desired. The below code streams a file from a container to the filesystem.
var fs = require('fs')
var thunderhead = new (require('thunderhead'))({
username : 'RackspaceUsername',
apikey : 'RackspaceKey',
region : 'ORD'
});
var writeStream = fs.createWriteStream('DestinationPath');
writeStream.on('end', function() { console.log('Done'); });
writeStream.on('error', function(err) { console.log("file stream error", err); });
thunderhead.storage.getObject({
container : 'containerName',
object : 'objectName'
}).pipe(writeStream);
There is an included Express application which is provided as a documentation source for the different Thunderhead methods and allows for executing test calls. It can be started as follows.
cp demo/public/config.example.js demo/public/config.js
# update demo/public/config.js with your Rackspace api values
cd demo
node ./server.js
The demo server will now be running at http://localhost:8080
Tests are run using Mocha and should.
npm install -g mocha
nom install -g should
cp test/apiConfig.example.js test/apiConfig.js
# update test/apiConfig.js with your Rackspace api values
mocha
Copyright © 2013 Cogsy licensed under the MIT License
