LifeAstroAPILifeAstroAPI

← Docs home

Add a Hindu Festival Calendar to Your Website or App

Build a city-specific Hindu festival calendar with a REST request, daily Panchang and Ekadashi examples in TypeScript, and a ready-to-render HTML month grid.

This tutorial builds a small Hindu calendar for any city: today's panchang with the time each element ends, the month's festivals with the window that decided each date, and the next Ekadashis with their parana window. The complete program is on GitHub: examples/hindu-calendar. It costs about 80 credits per run, well inside the free tier.

Fetch the festival dates for one city

Use the monthly festivals endpoint to put local observance dates on a temple website or an app. The API returns dates and observance windows for the location you supply. Keep your own event times, venue and booking details alongside the festival data.

curl "https://api.lifeastroapi.com/v1/festivals/month?year=2027&month=10&lat=28.6139&lon=77.209" \
  -H "Authorization: Bearer YOUR_API_KEY"

The returned festivals array includes each observance's local date and name, with windows where applicable. Display the returned date directly on the calendar grid. It is a calendar date for the location you requested.

See recorded festival JSON in the Playground · Estimate your calendar usage

Build a calendar with the Node SDK

npm install [email protected]
export LIFEASTRO_API_KEY=dv_live_...   # free key: lifeastroapi.com/signup

Keep the key on a server or in your terminal. Never ship it inside a browser or mobile bundle.

Fetch Panchang, festivals and Ekadashi

import { LifeAstro } from 'lifeastroapi';

const astro = new LifeAstro({ apiKey: process.env.LIFEASTRO_API_KEY });

// 1. City -> latitude, longitude, IANA timezone (free endpoint).
const { results } = await astro.geo.search({ q: 'Toronto', limit: 1 });
const loc = { lat: results[0].latitude, lon: results[0].longitude, tz: results[0].timezone };

// Today's date as the city sees it.
const today = new Intl.DateTimeFormat('en-CA', { timeZone: loc.tz }).format(new Date());
const [year, month] = today.split('-').map(Number);

// 2. Three calls in parallel.
const [panchang, monthRes, ekadashis] = await Promise.all([
  astro.panchang.advanced({ ...loc, date: today, time: '06:00' }),       // 30 credits
  astro.festivals.month({ ...loc, year, month, monthSystem: 'purnimanta' }), // 20 credits
  astro.festivals.vrat({ ...loc, year, type: 'ekadashi' }),              // 30 credits
]);

Always pass the city's own latitude, longitude and IANA timezone. Festival dates depend on local sunrise, moonrise and evening twilight, so the same festival can fall on a different day in Toronto and New Delhi.

Read festival and parana windows

Each festival comes with the windows that decided it. Karwa Chauth in Toronto, decided at moonrise:

{
  "date": "2026-10-28",
  "name_en": "Karwa Chauth",
  "importance": "major",
  "windows": [
    { "label": "moonrise", "start": "19:38" },
    { "label": "tithi", "start": "…", "end": "…" }
  ]
}
// The window that decided the date: pradosh kaal, moonrise, aparahna …
const deciding = (f) => f.windows?.find((w) => w.label !== 'tithi');

// Each Ekadashi carries its parana (fast-breaking) window for the next morning.
const parana = (f) => f.windows?.find((w) => w.label === 'parana');

Use monthSystem: 'amanta' for South, West and East Indian month names, and read the panchang's hindu_month.name_amanta or name_purnimanta to match.

Handle API errors

import { LifeAstroError } from 'lifeastroapi';

try {
  await astro.festivals.month({ ...loc, year, month });
} catch (e) {
  if (e instanceof LifeAstroError) {
    // e.status: HTTP status; e.code: e.g. 'insufficient_credits', 'unauthorized'
    console.error(e.status, e.code, e.message);
  }
}

Render or export the calendar

Toronto, Ontario, CA  ·  America/Toronto  ·  Sat, 10 Oct 2026

Today
  Saturday, Ashwin Krishna paksha (purnimanta)
  Sunrise 07:25   Sunset 18:42   Moonrise 07:27
  Tithi      Amavasya until 11:50
  Nakshatra  Hasta until 12:12
  Yoga       Indra until 12:32
  Rahu Kaal  10:14–11:39

Run npm run html -- --city "New Delhi" --locale hi in the example to also get a month grid as a single HTML file, with Hindi names next to English.

Next steps