# A panchang widget you host, for any location

> A small Node server and a framework-free script that show today's panchang for any coordinates - tithi with its end time, nakshatra, yoga, karana, sunrise, sunset and Rahu Kaal in the place's own time - styled your way and paid for by your own key.

Source: https://astronode.dev/templates/panchang-widget · Updated: 2026-12-05

## What it does

- `GET /api/panchang?lat=&lng=&tz=&date=` on your server calls both endpoints in parallel and returns compact JSON; the browser never sees your key.
- Works out the UTC offset at the place's local noon from its IANA zone, so daylight-saving changes come out right.
- Caches per place (coordinates rounded to two decimals) and date, shares in-flight requests, and never caches a failure.
- `public/widget.js` renders into any `<div data-astronode-panchang data-lat data-lng data-tz>` with `textContent` only; colours are CSS variables, with a dark scheme.
- Times on another local day carry the date, for example a tithi ending at 00:52 the next morning.

## Endpoints and plan

*API calls the template makes*

| Endpoint | Used for | Plan |
| --- | --- | --- |
| `POST /v1/panchang` | Tithi, nakshatra, yoga, karana, sunrise, sunset | Free |
| `POST /v1/muhurta/inauspicious` | Rahu Kaal | Hobby |

It needs a Hobby key or above: at least one endpoint it calls is not on the Free plan. See [pricing](https://astronode.dev/pricing).

## Where things live

| File | What it holds |
| --- | --- |
| `server.js` | The HTTP server: the JSON endpoint and the static files |
| `src/panchang.js` | Validation, offsets, the two API calls, the cache, response mapping |
| `public/widget.js` | The framework-free widget |
| `public/index.html` | A demo page with three widgets |

## Keys and deployment

- The API key is read from the server's environment and sent as `Authorization: Bearer <key>`; it never reaches a browser or an app bundle.
- `npm run check` runs 22 tests offline - validation, request bodies, daylight-saving offsets, mapping against recorded responses, the cache and the HTTP server - with no key and no network.
- Run the server anywhere Node runs and point the widget's script at it; or move `src/panchang.js` into your own backend's route.
- Upstream rate limits come back as 429; other API failures become 502, or 504 when the API cannot be reached.

## Questions

**Why does the panchang widget need the Hobby plan?**

Rahu Kaal comes from `POST /v1/muhurta/inauspicious`, a Hobby endpoint. The panchang itself is on Free; drop the Rahu Kaal call to run it on a Free key.

**How many API calls does it make?**

Two per place per day, whatever the traffic: the answer is cached per rounded location and date.

## Related pages

- [Use case: panchang widget](https://astronode.dev/use-cases/panchang-widget)
- [Recipe: daily panchang for a city](https://astronode.dev/recipes/daily-panchang-for-a-city)
- [All templates](https://astronode.dev/templates)
