nodejitsu-api v0.6.6
nodejitsu-api
The nodejitsu-api is a module that allows you to communicate with the our
RESTful API
Installation:
This module is published in NPM:
npm install nodejitsu-api --saveThe --save tells NPM to automatically add it to your package.json file
API documentation
Before you can use the API you need to create a new API client. In this example
we are going to assume that foo is your username and bar is the password of
Nodejitsu account you want to control.
api.createClient(options)
The createClient method generates a new API client. It accepts an options
argument which is used to configure the client.
options:
usernamestring The username of your Nodejitsu accountpasswordstring The password or auth token of your accountremoteUristring The Nodejitsu API resourcedebugboolean Output debugging information to the consoleproxystring HTTP proxy to connect overtimeoutnumber How long can a single API requests before we time it outignorePoweredByboolean Ignore the check for thex-powered-byheader
This options argument can either be an object with the properties specified above or a nconf object.
The remoteUri argument is a required argument. Most API calls also require the
username and password to be specified. There a couple of API call where this
is not required, this is documented by the relevant API calls.
var api = require('nodejitsu-api');
// Construct a new client.
var client = api.createClient({
username: 'foo',
password: 'bar',
remoteUri: 'https://api.nodejitsu.com'
});client
The API calls are generally constructed as resource and action:
client.resource.action('data', function (err, result) {
if (err) {
throw err;
}
// Use the result
});The following API resources are exposes in the module:
- apps Manage your application instances.
- databases Manage your databases.
- logs Manage your application logs.
- snapshots Manage your application snapshots.
- users Manage your Nodejitsu account.
- users.auth
- users.create
- users.available
- users.view
- users.confirm
- users.forgot
- users.update
- users.destroy
client.app
client.apps.available
Checks if the available of the applications name and sub domain is currently taken in Nodejitsu.
Arguments
appstring The application namecallbackfunction
client.app.available('my-application', function (err, data) {
console.log(data);
});client.apps.list
List all the applications for the authenticated user.
Arguments
usernamestring The username, which is optional and will default to the configured usernamecallbackfunction The callback receives an array of your applications
client.app.list('my-application', function (err, data) {
console.log(data);
});client.apps.create
Create an application from the specified package.json object.
Arguments
appobject The package.jsoncallbackfunction
var app = require('./package.json'); // requires your package.json as example
client.apps.create(app, function (err, data) {
console.log(data);
});client.apps.view
Views the application details for one specific application.
Arguments
appstring Name of the applicationcallbackfunction The callback receives your application details
client.apps.view('my-application-name', function (err, data) {
console.log(data);
});client.apps.update
Updates the the application details.
Arguments
appstring Name of the applicationchangesObject Properties that need to be updated for this applicationcallbackfunction
client.apps.update('my-application-name', { name: 'foo' }, function (err, data) {
console.log(data);
});client.apps.start
Start the application.
Arguments
appstring Name of the applicationcallbackfunction
client.apps.start('my-application-name', function (err, data) {
console.log(data);
});client.apps.stop
Stop the application.
Arguments
appstring Name of the applicationcallbackfunction
client.apps.stop('my-application-name', function (err, data) {
console.log(data);
});client.apps.restart
Restarts the application without changing a drone. Where stopping and starting an application could result in deployment on a different drone.
Arguments
appstring Name of the applicationcallbackfunction
client.apps.stop('my-application-name', function (err, data) {
console.log(data);
});client.apps.setDrones
Run the application on x amount of drones on the Nodejitsu servers.
Arguments
appstring Name of the applicationdronesnumber The amount of drones the application needs to run oncallbackfunction
client.apps.setDrones('my-application-name', 10, function (err, data) {
console.log(data);
});client.apps.datacenter
Move the application to a new datacenter.
Arguments
appstring Name of the applicationcloudobject The datacenter configurationproviderstring Name of the cloud providerdatacenterstring Data center identifierdronesnumber The amount of drones you want to start on this datacenter
callbackfunction
var cloud = {
provider: 'joyent',
datacenter: 'eu-ams-1',
drones: 6
}
client.apps.datacenter('my-application-name', cloud, function (err, data) {
console.log(data);
});client.apps.destroy
Destroys the application.
Arguments
appstring Name of the applicationcallbackfunction
client.apps.destroy('my-application-name', function (err, data) {
console.log(data);
});client.apps.endpoints
Get a list of all datacenter providers and datacenter identifiers. Please note: this method doesn't require any authentication.
Arguments
callbackfunction
client.apps.destroy('my-application-name', function (err, data) {
console.log(data);
});client.databases
client.databases.create
Create a new database. These databases are created by third party providers you can find more information about each database provider in webops/databases
Arguments
typestring Database type (mongo, monghq, redis, redistogo, couch)namestring Name of the databasecallbackfunction
client.databases.create('redis', 'my-iriscouch-redis-db', function (err, data) {
console.log(data);
});client.databases.get
Get the database information which contains the connection details
Arguments
namestring Name of the databasecallbackfunction
client.databases.get('my-iriscouch-redis-db', function (err, data) {
console.log(data);
});client.databases.list
Get the all databases and their information.
Arguments
usernamestring The username, which is optional and will default to the configured usernamecallbackfunction
client.databases.list('username', function (err, data) {
console.log(data);
});client.databases.destroy
Destroy the specified database.
Arguments
namestring Name of the database you want to destroycallbackfunction
client.databases.list('username', function (err, data) {
console.log(data);
});client.logs
client.logs.byApp
Fetches the logs for the given application.
Arguments
namestring Name of the applicationamountnumber The amount logs to retrievecallbackfunction
client.logs.byApp('my-application', 50, function (err, data) {
console.log(data);
});client.logs.byUser
Fetches the logs for every application for the specified user.
Arguments
usernamestring The username, which is optional and will default to the configured usernameamountnumber The amount logs to retrievecallbackfunction
client.logs.byUser('foo', 50, function (err, data) {
console.log(data);
});client.snapshots
client.snapshots.list
Lists all snapshots for the given application
Arguments
namestring Name of the applicationcallbackfunction
client.snapshots.list('my-application', function (err, data) {
console.log(data);
});client.snapshots.create
Uploads a new snapshot for the application. This method assumes that you have a
properly packed .tgz application on your system. The .tgz should have the
same internal structure as the result of an npm pack.
Arguments
namestring Name of the application that receives the snapshotsnapshotname: string Name of the snapshotlocation: string absolute path to the.tgzsnapshotcallbackfunction
client.snapshots.create('my-application', '0.1.0', '/app.tgz', function (err, data) {
console.log(data);
});Please note that this method returns an event emitter which you can use to track
the progress of the upload. This event emitter emits and data event with the
amount of data uploaded and emits the end event once the upload been
completed.
client.snapshots.fetch
Fetches the snapshot from your application. Please note that these snapshots are
the actual state of the application that is ran on the drones, so these will
contain the node_modules folder.
Arguments
namestring Name of the applicationsnapshotnamestring Name of the snapshot that you want to downloadcallbackfunction
client.snapshots.fetch('my-application', '0.1.0', function (err, data) {
console.log(data);
});This function returns the Stream that fetches the snapshot. You can use
this Stream to Stream.pipe it to a file on your system. The callback would
only indicate a successful fetch.
client.snapshots.destroy
Destroy the snapshot.
Arguments
namestring Name of the applicationsnapshotnamestring Name of the snapshot that you want to downloadcallbackfunction
client.snapshots.destroy('my-application', '0.1.0', function (err, data) {
console.log(data);
});client.snapshots.activate
Activates a snapshot. This allows you to roll back to a old version when something goes wrong in your application.
Arguments
namestring Name of the applicationsnapshotnamestring Name of the snapshot that you want to downloadcallbackfunction
client.snapshots.activate('my-application', '0.0.45', function (err, data) {
console.log(data);
});client.users
client.users.auth
Tests if the users login details are valid.
Arguments
callbackfunction
client.users.auth(function (err, authenticated) {
console.log(authenticated);
});client.users.create
Register a new Nodejitsu account. Please note: this method doesn't require any authentication.
Arguments
accountobject account detailsusernamestring usernamepassowrdstring passwordemailstring e-mail address that receives the verification code
callbackfunction
var account = {
username: 'foo',
password: 'bar',
email: 'foo@example.com'
};
client.users.create(account, function (err, data) {
console.log(data);
});client.users.available
Test if the username is available. Please note: this method doesn't require any authentication.
Arguments
usernamestring usernamecallbackfunction
client.users.available('foo', function (err, data) {
console.log(data);
});client.users.view
Retrieves the user details.
Arguments
usernamestring usernamecallbackfunction
client.users.view('foo', function (err, data) {
console.log(data);
});client.users.confirm
Confirm the e-mail address of the user. Please note: this method doesn't require any authentication.
Arguments
userobject confirmation detailsusernamestring the username that we are confirminginviteCodestring the inviteCode that was send to the users e-mail
callbackfunction
var user = {
username: 'foo',
inviteCode: 'foo-bar-bnanan-trololol'
};
client.users.confirm(user, function (err, data) {
console.log(data);
});client.users.forgot
Request a password reset e-mail
Arguments
usernamestring usernamecallbackfunction
client.users.forgot('foo', function (err, data) {
console.log(data);
});client.users.update
Updates the account information.
Arguments
usernamestring usernamechangesObject Properties that need to be updated for this user.callbackfunction
client.users.update('foo', changes, function (err, data) {
console.log(data);
});client.users.destroy
Removes your account from the Nodejitsu platform. Use with extreme caution. This will also destroy all the applications that you are running and databases that you have created. Once you call this method, there is no way back and no option to undo this.
Arguments
usernamestring usernamecallbackfunction
client.users.destroy('foo', function (err, data) {
console.log(data);
});Tests
All tests are written with vows and should be run with npm:
$ npm testLicense
MIT.
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago