Checkly CLI

7.12.0 · active · verified Wed Apr 22

The Checkly CLI provides a JavaScript/TypeScript-native workflow for implementing "monitoring as code," allowing developers to define, test, and deploy synthetic monitoring checks directly from their codebase. This approach integrates monitoring into the development pipeline, enabling version control, code reviews, and automated deployments. The current stable version is 7.12.0, with minor releases occurring frequently, often weekly or bi-weekly. Key differentiators include first-class support for `@playwright/test` for browser checks, a TypeScript-first design for robust type-checking and autocompletion, and the flexibility to run checks either on the Checkly cloud platform or within private locations on-premise, emphasizing a developer-centric experience.

Common errors

Warnings

Install

Imports

Quickstart

This code defines a simple API check and a Playwright-based browser check for a webshop, demonstrating how to write monitoring as code. It includes instructions for local testing and deployment to the Checkly cloud via the CLI.

import { ApiCheck, AssertionBuilder } from 'checkly/constructs';
import { test, expect } from '@playwright/test';
import * as path from 'path';

// --- API Check Example (api.check.ts) ---
// Define an API check for a public endpoint.
new ApiCheck('books-api-check-1', {
  name: 'Books API Status',
  request: {
    url: 'https://danube-web.shop/api/books',
    method: 'GET',
    assertions: [
      AssertionBuilder.statusCode().equals(200),
      AssertionBuilder.jsonBody('$[0].id').isNotNull(),
    ],
  },
});

// --- Browser Check Example (homepage.spec.ts) ---
// Define a Playwright-based browser check for a homepage.
test('webshop homepage loads and has title', async ({ page }) => {
  const response = await page.goto('https://danube-web.shop');
  expect(response?.status()).toBeLessThan(400); // Expect a successful HTTP status code
  await expect(page).toHaveTitle(/Danube WebShop/);

  // Optionally take a screenshot upon successful load
  const screenshotPath = path.join(process.cwd(), 'homepage.jpg');
  await page.screenshot({ path: screenshotPath });
  console.log(`Screenshot saved to: ${screenshotPath}`);
});

// To run these checks after saving them in your project (e.g., in `__checks__` directory):
// 1. Install Checkly CLI and Playwright: `npm install --save-dev checkly @playwright/test`
// 2. Log in to your Checkly account: `npx checkly login` (Requires a Checkly account)
// 3. Run tests locally: `npx checkly test`
// 4. Deploy checks to the Checkly cloud: `npx checkly deploy`

view raw JSON →