JavaScript Bible API Example: Verse of the Day Bot (Node.js)

Fetch a random Bible verse using a JSON Bible API — then schedule it daily with Node.js and cron.

Last updated: February 2026


What You Will Build

This tutorial demonstrates a production-ready JavaScript Bible API integration — including secure environment variables, error handling, and scheduling.


Prerequisites

Initialize Project
mkdir verse-bot
cd verse-bot
npm init -y

Step 1: Secure Your API Key

Never hardcode API keys — use environment variables instead.

Set Environment Variable (Mac / Linux)
export BIBLEBRIDGE_API_KEY=your_api_key_here

Step 2: JavaScript Bible API Example (Node.js)

Verse of the Day Script (verse.js)

"use strict";

const API_BASE = "https://holybible.dev/api/scripture";
const API_KEY = process.env.BIBLEBRIDGE_API_KEY;

if (!API_KEY) {
  throw new Error("Missing BIBLEBRIDGE_API_KEY environment variable.");
}

// Curated verses to avoid incomplete passages
const VERSES = [
  { bookID: 19, chapter: 23, verse: 1 },
  { bookID: 43, chapter: 3, verse: 16 },
  { bookID: 20, chapter: 3, verse: 5 }
];

function pickRandomVerse() {
  return VERSES[Math.floor(Math.random() * VERSES.length)];
}

async function fetchVerse(ref) {
  const params = new URLSearchParams({
    bookID: ref.bookID,
    chapter: ref.chapter,
    verse: ref.verse,
    version: "KJV"
  });

  const response = await fetch(`${API_BASE}?${params}`, {
    headers: {
      Authorization: `Bearer ${API_KEY}`
    }
  });

  if (!response.ok) {
    throw new Error(`API request failed (${response.status})`);
  }

  return response.json();
}

async function run() {
  const ref = pickRandomVerse();
  const verse = await fetchVerse(ref);

  const formatted =
    `${verse.book.name} ${verse.chapter}:${verse.data.verse}\n` +
    `${verse.data.text}`;

  console.log(formatted);
}

run().catch(console.error);

Example Output

Console Output

John 3:16
For God so loved the world, that he gave his only begotten Son,
that whosoever believeth in him should not perish, but have everlasting life.

Step 3: Schedule with Cron (Daily Execution)

Cron Job – Runs Daily at 8:00 AM

0 8 * * * /usr/bin/node /path/to/verse.js >> /path/to/output.log 2>&1

Optional: Send to Discord via Webhook

Discord Webhook Integration

const DISCORD_WEBHOOK = process.env.DISCORD_WEBHOOK;

await fetch(DISCORD_WEBHOOK, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ content: formatted })
});

Common Errors & Fixes


Frequently Asked Questions

Is this a free Bible API?

Yes — you can sign up for a free API key to begin development.

Does this return JSON?

Yes. All Scripture responses are returned in structured JSON format.

Can I change translations?

Yes. Modify the version parameter (for example: KJV, NIV).

Can I fetch multiple verses?

Yes. The API supports ranges and full chapter queries. See the Bible API documentation for details.


Next Steps

Explore the full JSON Bible API documentation for advanced endpoint usage.