npm package: @lxgicstudios/api-health
Description: Check if API endpoints are alive and responding. Single URL or batch from JSON. Status codes, response times, SSL validity, and continuous monitoring.
Author: LXGIC Studios
Latest version: 1.0.0

# @lxgicstudios/api-health

[![npm version](https://img.shields.io/npm/v/@lxgicstudios/api-health)](https://www.npmjs.com/package/@lxgicstudios/api-health)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-0-blue)](https://www.npmjs.com/package/@lxgicstudios/api-health)

Check if your API endpoints are alive and responding. Single URL or batch from a JSON file. Get status codes, response times, SSL certificate info, and set up continuous monitoring.

**Zero external dependencies.** Uses only Node.js builtins.

## Install

```bash
npm install -g @lxgicstudios/api-health
```

Or run directly:

```bash
npx @lxgicstudios/api-health https://api.example.com/health
```

## Usage

### Check a single endpoint

```bash
api-health https://api.example.com/health
```

### Check multiple endpoints from a file

```bash
api-health --file endpoints.json
```

Where `endpoints.json` looks like:

```json
[
  "https://api.example.com/health",
  {"url": "https://api2.example.com", "name": "Backup API"}
]
```

### Continuous monitoring

```bash
api-health --watch https://api.example.com --interval 10000
```

### Assert a specific status code

```bash
api-health https://api.example.com --assert 200
```

Returns exit code 1 if the assertion fails. Great for CI/CD pipelines.

### Check SSL certificate

```bash
api-health --ssl https://api.example.com
```

### JSON output

```bash
api-health https://api.example.com --json
```

## Features

- Single URL or batch checking from JSON files
- Response time measurement for every request
- SSL certificate validity and expiration warnings
- Continuous monitoring with configurable intervals
- Status code assertions for CI/CD pipelines
- Colorful terminal output with clear pass/fail indicators
- JSON output mode for piping to other tools
- Named endpoints for easy identification
- Summary stats when checking multiple endpoints
- Exit code 1 on failures (great for automation)

## Options

| Option | Alias | Description | Default |
|--------|-------|-------------|---------|
| `--help` | `-h` | Show help message | |
| `--json` | | Output results as JSON | `false` |
| `--file <path>` | `-f` | Load URLs from a JSON file | |
| `--timeout <ms>` | `-t` | Request timeout in milliseconds | `10000` |
| `--assert <code>` | `-a` | Expect a specific HTTP status code | |
| `--watch` | `-w` | Continuously monitor endpoints | `false` |
| `--interval <ms>` | `-i` | Watch interval in milliseconds | `30000` |
| `--ssl` | | Check SSL certificate validity | `false` |

## Exit Codes

| Code | Meaning |
|------|---------|
| `0` | All endpoints healthy, all assertions passed |
| `1` | One or more endpoints down or assertions failed |

---

**Built by [LXGIC Studios](https://lxgicstudios.com)**

[GitHub](https://github.com/lxgicstudios/api-health) | [Twitter](https://x.com/lxgicstudios)