A minimal Node.js application that repeatedly calls an API endpoint at configurable intervals.
-
Install dependencies:
npm install
-
Create environment configuration:
cp .env.example .env
Then edit
.envwith your actual values.
Configure the application using environment variables in the .env file:
- API_URL (required): The full URL to call
- API_HEADERS (optional): A JSON string representing HTTP headers
- CALL_INTERVAL_MS (required): Interval between calls in milliseconds
| Variable | Required | Description | Example |
|---|---|---|---|
API_URL |
✅ | The full URL to call | https://api.example.com/health |
API_HEADERS |
❌ | HTTP headers as JSON string | {"Authorization": "Bearer token123"} |
CALL_INTERVAL_MS |
✅ | Interval between calls in milliseconds | 5000 (5 seconds) |
API_URL=https://api.example.com/health
API_HEADERS={"Authorization": "Bearer your-token-here", "Content-Type": "application/json"}
CALL_INTERVAL_MS=60000npm startStarting API heartbeat to https://api.example.com/health every 60000ms
[2025-08-25T10:30:00.000Z] Status: 200 OK
[2025-08-25T10:31:00.000Z] Status: 200 OK
[2025-08-25T10:32:00.000Z] Error: fetch failed