QuranJS

Getting Started

Install and configure @quranjs/api - a TypeScript SDK for the Quran.com API.

Installation

npm install @quranjs/api

Quick Start

import { Language, QuranClient } from "@quranjs/api";

// Initialize the client
const client = new QuranClient({
  clientId: process.env.QURAN_CLIENT_ID!,
  clientSecret: process.env.QURAN_CLIENT_SECRET!,
  defaults: {
    language: Language.ENGLISH,
  },
});

// Fetch all chapters
const chapters = await client.chapters.findAll();

// Get a specific verse
const verse = await client.verses.findByKey("2:255", {
  translations: [20],
  words: true,
});

// Search
const results = await client.search.search("light", {
  language: Language.ENGLISH,
  size: 10,
});

Environment Variables

# .env
QURAN_CLIENT_ID=your_client_id
QURAN_CLIENT_SECRET=your_client_secret
const client = new QuranClient({
  clientId: process.env.QURAN_CLIENT_ID!,
  clientSecret: process.env.QURAN_CLIENT_SECRET!,
});

Runtime Configuration

// Get current config
const config = client.getConfig();

// Update config
client.updateConfig({
  defaults: { language: Language.ARABIC },
});

// Clear auth token
client.clearCachedToken();

Last updated on