Node.js client
NEW

Automate your Calibre system using the official Node.js client library.

The calibre npm package is what we use to distribute our command line interface. It also exports a Node.JS API that can be used to automate Calibre from Node.

Installation

Step 1 Install using NPM

$ npm install calibre --save

Step 2 Generate an API Access Token, set it as an environment variable. We recommend using dotenv to handle environment variables.

// In a .env file
CALIBRE_API_TOKEN=<my-token>

Step 3 Write some node!

The example below will create a single page test of the calibreapp.com/cli page from Sydney, emulating an iPhone 8 using an emerging market connection speed.

Node 8+ required to run this example.

// ES6
const { Test } = require('calibre')

const url = 'https://calibreapp.com/cli'
const location = 'Sydney'
const device = 'iPhone8'
const connection = 'emergingMarkets'

const { uuid } = await Test.create({
  url,
  location,
  device,
  connection
})

const results = await Test.waitForTest(uuid)
console.log(JSON.stringify(results, null, 2))

You will find this and other examples in the Git repository.

In case of any questions about the API usage we encourage posting questions on the CLI issue tracker.