{"id":18747,"library":"resilient-consul","title":"resilient-consul","description":"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.","status":"active","version":"0.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/h2non/resilient-consul","tags":["javascript","fault","tolerant","balance","ajax","http","https","xhr","request"],"install":[{"cmd":"npm install resilient-consul","lang":"bash","label":"npm"},{"cmd":"yarn add resilient-consul","lang":"bash","label":"yarn"},{"cmd":"pnpm add resilient-consul","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; middleware is designed for resilient.js HTTP client","package":"resilient","optional":false}],"imports":[{"note":"ESM default export; CJS require works but is not idiomatic for modern JS.","wrong":"const consul = require('resilient-consul')","symbol":"default","correct":"import consul from 'resilient-consul'"},{"note":"Named export also available; be consistent but default is simpler.","wrong":"import consul from 'resilient-consul'","symbol":"consul","correct":"import { consul } from 'resilient-consul'"},{"note":"resilient.js uses CJS; ESM imports work with bundlers.","wrong":"const Resilient = require('resilient')","symbol":"Resilient","correct":"import Resilient from 'resilient'"}],"quickstart":{"code":"import Resilient from 'resilient';\nimport consul from 'resilient-consul';\n\nconst client = Resilient();\n\nclient.use(consul({\n  service: 'web',\n  servers: ['http://localhost:8500'],\n  datacenter: 'dc1',\n  tag: '1.0',\n  onlyHealthy: true,\n  mapServers: (list) => list.map(svc => svc.ServiceAddress + '/v1')\n}));\n\nclient.get('/api/health', (err, res) => {\n  if (err) console.error('Error:', err);\n  else console.log('Response:', res);\n});","lang":"typescript","description":"Creates resilient HTTP client with Consul discovery using service 'web' from local Consul agent."},"warnings":[{"fix":"Migrate to another HTTP client with Consul support (e.g., axios + consul library).","message":"resilient.js is no longer actively maintained; consider alternatives.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Add 'Access-Control-Allow-Origin': '*' to Consul config http_api_response_headers.","message":"In browser, Consul CORS must be enabled; otherwise requests fail silently.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use 'http://consul-host:8500' not 'consul-host'.","message":"The 'servers' option requires full URLs including protocol and port.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure mapServers handles health check response structure (array of objects with Service key).","message":"If 'onlyHealthy' is true, health endpoint may return different data structure than catalog.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import consul from 'resilient-consul'` or `const consul = require('resilient-consul')`.","cause":"Default import used when package exports object with consul property.","error":"TypeError: consul is not a function"},{"fix":"Install resilient: `npm install resilient`.","cause":"Missing peer dependency resilient.js.","error":"Error: Cannot find module 'resilient'"},{"fix":"Import Resilient: `import Resilient from 'resilient'` or `const Resilient = require('resilient')`.","cause":"Resilient constructor not imported correctly.","error":"ReferenceError: Resilient is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}