heroku-client
A wrapper around the v3 Heroku API.
Install
$ npm install heroku-client --save
Usage
var Heroku = require('heroku-client'),
heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN });
heroku.apps().list(function (err, apps) {
});
var app = heroku.apps('my-app');
app.info(function (err, app) {
});
app.dynos().list(function (err, dynos) {
});
app.collaborators('user@example.com').delete(function (err, collaborator) {
});
var app = heroku.apps('another-app'),
user = { email: 'new-user@example.com' };
app.collaborators().create({ user: user }, function (err, collaborator) {
});
Promises
heroku-client works with Node-style callbacks, but also implements promises with the Q library.
var q = require('q');
heroku.apps().list().then(function (apps) {
return q.all(apps.map(function (app) {
return heroku.apps(app.name).dynos().list();
}));
}).then(function (dynos) {
console.log(dynos);
});
Caching
When NODE_ENV
is set to "production", heroku-client will create a memcached client using memjs. See the memjs repo for configuration instructions.
For local development with caching, it's enough to start a memcached server and set MEMCACHIER_SERVERS
to 0.0.0.0:11211
in your .env
file.
You will also need to pass an option called cacheKeyPostfix
when creating your heroku-client client:
var heroku = new Heroku({ token: user.apiToken, cacheKeyPostfix: user.id });
This ensures that API responses are cached and properly scoped to the user that heroku-client is making requests on behalf of.
Contributing
Running tests
node-heroku uses jasmine-node for tests:
$ npm test