Node.js API

Use the Node API when you want to run React Doctor from another script or service.

import { diagnose, summarizeDiagnostics, toJsonReport } from "react-doctor/api";

const result = await diagnose("./path/to/your/react-project");

console.log(result.score); // { score: 82, label: "Great" } or null
console.log(result.diagnostics); // Diagnostic[]
console.log(result.project); // detected framework, React version, etc.

Diagnose options

diagnose accepts a second options object:

const result = await diagnose("./path/to/your/react-project", {
  lint: true,
});

Scan multiple projects

Pass diagnose an object with projects to scan several projects in one call. Use this for monorepos where each module needs its own score:

const result = await diagnose({
  projects: [
    { directory: "./modules/billing" },
    {
      directory: "./modules/payroll",
      config: { rules: { "react-doctor/no-danger": "off" } },
    },
  ],
  config: { ignore: { files: ["**/generated/**"] } },
  concurrency: 4,
});

console.log(result.score); // worst score across projects, or null
console.log(result.projects); // ProjectResult[], same order as input
console.log(result.diagnostics); // all diagnostics across projects

Projects run through a worker pool. concurrency caps how many scan at once (default 4); set it to 1 for sequential runs. Results keep input order.

Each entry in result.projects is either { ok: true, directory, ...DiagnoseResult } or { ok: false, directory, error }, so one failing project does not reject the whole batch.

Config layers additively, least to most specific: the project's on-disk doctor.config.*, then the batch-level config, then the per-project config. rules and categories merge per key, and ignore lists union, so a per-project override changes individual rules without discarding the base config.

Project entries also accept the same scan options as diagnose (lint, deadCode, and so on). Per-project values win over batch-level values.

JSON reports

Convert a result into the same report shape used by --json:

const report = toJsonReport(result, {
  version: "1.0.0",
});

Summarize diagnostics by severity and category:

const counts = summarizeDiagnostics(result.diagnostics);

Exported types and helpers

react-doctor/api exports:

  • diagnose
  • toJsonReport
  • summarizeDiagnostics
  • JsonReport
  • JsonReportSummary
  • JsonReportProjectEntry
  • JsonReportMode
  • buildJsonReport
  • buildJsonReportError

Use the CLI when you want terminal output, PR comments, or install flows. Use the API when you need to embed React Doctor in another tool.