Fetch a random Bible verse using a JSON Bible API — then schedule it daily with Node.js and cron.
Last updated: February 2026
This tutorial demonstrates a production-ready JavaScript Bible API integration — including secure environment variables, error handling, and scheduling.
fetch supportmkdir verse-bot
cd verse-bot
npm init -y
Never hardcode API keys — use environment variables instead.
export BIBLEBRIDGE_API_KEY=your_api_key_here
"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);
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.
0 8 * * * /usr/bin/node /path/to/verse.js >> /path/to/output.log 2>&1
const DISCORD_WEBHOOK = process.env.DISCORD_WEBHOOK;
await fetch(DISCORD_WEBHOOK, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content: formatted })
});
Yes — you can sign up for a free API key to begin development.
Yes. All Scripture responses are returned in structured JSON format.
Yes. Modify the version parameter (for example: KJV, NIV).
Yes. The API supports ranges and full chapter queries. See the Bible API documentation for details.
Explore the full JSON Bible API documentation for advanced endpoint usage.