Node.js · fetch

Use Backfire from Node.js

Node 18 and later ship a global fetch(), so no dependency is needed. The relay call is a POST with a JSON body; the envelope comes back as JSON you can branch on immediately.

Notes for this client

  • Works with the built-in fetch, axios, undici or got — no SDK to install.
  • Keep the key in process.env, never in source; revoke it from the dashboard when needed.
  • Send body as an object for JSON payloads, or body_base64 for binary uploads.
  • Check envelope.ok first, then read envelope.upstream.status for the upstream result.

Working example

node
const res = await fetch('https://backfireapi.base44.app/functions/forward', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.BACKFIRE_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://api.github.com/zen',
    method: 'GET',
    timeout_ms: 8000,
  }),
});

const envelope = await res.json();
if (!envelope.ok) throw new Error(envelope.error.code);

console.log(envelope.upstream.status);      // 200
console.log(envelope.body.text);            // upstream payload
console.log(envelope.meta.trips_charged);   // 1
console.log(envelope.quota.remaining);      // balance after the call

Questions about this

Other languages

Try it with 5,000 free trips.

No card, no subscription, and the balance never expires.