Get Bible verses in JavaScript and Node.js

This guide shows how to get Bible verses with plain JavaScript, first on a server with Node.js, then on a web page. Both use the built-in fetch, so there is nothing to install.

Shows both kinds of key: secret on servers, publishable on websites.

1. Get a free API key

Sign in at bibleverse-api.com with your email and create a key. Use a secret key (it starts with bva_sk_) on servers, and a publishable key (bva_pk_) on websites. A publishable key only works on the websites you list when you create it.

2. Fetch verses in Node.js

Node.js 18 and later include fetch. Keep the secret key in an environment variable, not in your code.

verses.mjs
const API = "https://api.bibleverse-api.com/v1";
const KEY = process.env.BIBLE_API_KEY; // bva_sk_…

async function getVerses(ref, bible = "kjv") {
  const url = `${API}/bibles/${bible}/passages?ref=${encodeURIComponent(ref)}`;
  const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
  const body = await res.json();
  if (!res.ok) throw new Error(body.error.message);
  return body;
}

const data = await getVerses("John 3:16-18");
for (const passage of data.passages) {
  console.log(passage.reference);
  for (const chapter of passage.chapters) {
    for (const v of chapter.verses) console.log(v.verse, v.text);
  }
}
console.log(data.attribution);

3. Or ask for plain text

Add format=text to get the reference, numbered verses and attribution as ready-to-show text.

plain-text.mjs
const res = await fetch(`https://api.bibleverse-api.com/v1/bibles/kjv/passages?ref=${encodeURIComponent("Psalm 23")}&format=text`, {
  headers: { Authorization: `Bearer ${process.env.BIBLE_API_KEY}` },
});
console.log(await res.text());

4. Show a verse on a web page

In the browser, use a publishable key. Secret keys are refused when a request comes from a web page, so they can't leak from your site's code.

index.html
<blockquote id="verse">Loading…</blockquote>
<script>
  const KEY = "bva_pk_…"; // publishable key, allowed on this website
  const ref = "Psalm 23:1";
  fetch("https://api.bibleverse-api.com/v1/bibles/kjv/passages?format=text&ref=" + encodeURIComponent(ref), {
    headers: { Authorization: "Bearer " + KEY },
  })
    .then((res) => res.text())
    .then((text) => { document.getElementById("verse").textContent = text; });
</script>

5. Handle errors and limits

Errors always look like { "error": { "code": "unknown_book", "message": "…" } }. Show message to people and check code in your program. A misspelled book returns a suggestion such as “Did you mean John?”.

When you reach a limit the API answers 429 with a Retry-After header in seconds. Wait that long before trying again.

Ready to try it?

The Free plan gives you 5,000 requests and 2,000 verses a day, with no card.

Get a free API keyRead the API docs