resilient-consul
raw JSON → 0.1.7 verified Sat Apr 25 auth: no javascript
Middleware for resilient.js HTTP client that integrates Consul as a service discovery server. Version 0.1.7 works with Consul HTTP API v1 and resilient.js >=0.3. Supports Node.js and browsers (via Bower or script tag). Provides fault-tolerant, load-balanced HTTP requests by querying Consul's catalog or health endpoint, allowing custom server mapping and per-service datacenter/tag filters. Differentiates by adding Consul discovery to resilient.js, enabling dynamic backend selection.
Common errors
error TypeError: consul is not a function ↓
cause Default import used when package exports object with consul property.
fix
Use
import consul from 'resilient-consul' or const consul = require('resilient-consul'). error Error: Cannot find module 'resilient' ↓
cause Missing peer dependency resilient.js.
fix
Install resilient:
npm install resilient. error ReferenceError: Resilient is not defined ↓
cause Resilient constructor not imported correctly.
fix
Import Resilient:
import Resilient from 'resilient' or const Resilient = require('resilient'). Warnings
deprecated resilient.js is no longer actively maintained; consider alternatives. ↓
fix Migrate to another HTTP client with Consul support (e.g., axios + consul library).
gotcha In browser, Consul CORS must be enabled; otherwise requests fail silently. ↓
fix Add 'Access-Control-Allow-Origin': '*' to Consul config http_api_response_headers.
gotcha The 'servers' option requires full URLs including protocol and port. ↓
fix Use 'http://consul-host:8500' not 'consul-host'.
gotcha If 'onlyHealthy' is true, health endpoint may return different data structure than catalog. ↓
fix Ensure mapServers handles health check response structure (array of objects with Service key).
Install
npm install resilient-consul yarn add resilient-consul pnpm add resilient-consul Imports
- default wrong
const consul = require('resilient-consul')correctimport consul from 'resilient-consul' - consul wrong
import consul from 'resilient-consul'correctimport { consul } from 'resilient-consul' - Resilient wrong
const Resilient = require('resilient')correctimport Resilient from 'resilient'
Quickstart
import Resilient from 'resilient';
import consul from 'resilient-consul';
const client = Resilient();
client.use(consul({
service: 'web',
servers: ['http://localhost:8500'],
datacenter: 'dc1',
tag: '1.0',
onlyHealthy: true,
mapServers: (list) => list.map(svc => svc.ServiceAddress + '/v1')
}));
client.get('/api/health', (err, res) => {
if (err) console.error('Error:', err);
else console.log('Response:', res);
});