How this page was checked: The backend handler and the app's fetchPanchang / localTime were executed on Node 24 (same fetch API as React Native) against the in-memory API. The screen component is JSX and was not rendered on a device.
Why the app cannot hold the key
Everything in a React Native bundle can be read back out of the installed app - including values from .env files that a build plugin inlines. Expo, for example, inlines every EXPO_PUBLIC_ variable into the JavaScript bundle; that prefix means "public", and it is the most common way an API key ends up in an app store. So the shape is always: app → your backend → AstroNode.
For the first call with this pattern see the React Native quickstart. This page builds a complete screen on it.
The backend: one endpoint, a trimmed response
A web-standard handler - mount it in Next.js, Hono, Express (via an adapter) or a serverless function:
const ASTRONODE = process.env.ASTRONODE_BASE_URL ?? "https://api.astronode.dev";
export async function handlePanchang(req: Request): Promise<Response> {
const q = new URL(req.url).searchParams;
const body = {
date: q.get("date"),
tz_offset_minutes: Number(q.get("tz")),
lat: Number(q.get("lat")),
lng: Number(q.get("lng")),
};
const res = await fetch(`${ASTRONODE}/v1/panchang`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const json = await res.json();
if (!res.ok) return Response.json({ code: json.error.code }, { status: res.status });
const p = json.data;
// Send the app only what the screen shows.
return Response.json({
vara: p.vara.name,
tithi: `${p.tithi.paksha} ${p.tithi.name}`,
nakshatra: p.nakshatra.name,
yoga: p.yoga.name,
karana: p.karana.name,
sunrise: p.sunrise,
sunset: p.sunset,
});
}Query parameters are strings, so the handler converts them with Number(...) before the call. Sending "330" instead of 330 is a 400 VALIDATION_ERROR ("expected number, received string"). Trimming the payload also keeps the mobile response small and lets you change providers or fields without an app release.
The app: fetch, then convert times
api.ts in the app - no key, just your server:
export type Panchang = {
vara: string; tithi: string; nakshatra: string; yoga: string; karana: string;
sunrise: string; sunset: string;
};
export async function fetchPanchang(apiBase: string, date: string, tz: number, lat: number, lng: number): Promise<Panchang> {
const qs = new URLSearchParams({ date, tz: String(tz), lat: String(lat), lng: String(lng) });
const res = await fetch(`${apiBase}/panchang?${qs}`);
if (!res.ok) throw new Error(`panchang ${res.status}`);
return res.json();
}
// Display times in the user's offset, not the phone's: the API returns UTC instants.
export const localTime = (iso: string, tzOffsetMinutes: number): string => {
const d = new Date(Date.parse(iso) + tzOffsetMinutes * 60_000);
return d.toISOString().slice(11, 16);
};| Field | Value |
|---|---|
| vara | Mangalavara |
| tithi | Krishna Ashtami |
| nakshatra / yoga / karana | Magha / Vaidhriti / Balava |
| sunrise | 2026-12-01T01:25:17.000Z → localTime(…, 330) = 06:55 |
| sunset | 2026-12-01T12:29:26.000Z → 17:59 |
Rendering it:
function PanchangCard({ p, tz }: { p: Panchang; tz: number }) {
return (
<View style={{ padding: 16, gap: 6 }}>
<Text style={{ fontSize: 18, fontWeight: "600" }}>{p.vara} · {p.tithi}</Text>
<Text>Nakshatra {p.nakshatra} · Yoga {p.yoga} · Karana {p.karana}</Text>
<Text>Sunrise {localTime(p.sunrise, tz)} · Sunset {localTime(p.sunset, tz)}</Text>
</View>
);
}The mistakes that bite first
- The key in an `EXPO_PUBLIC_` (or `react-native-config`) variable. It works on the first try and is readable from every install. Move the call behind your backend and rotate the key.
- Formatting UTC with the phone's time zone.
new Date(p.sunrise).toLocaleTimeString()shows sunrise in the zone the phone is in, not the city the panchang is for. A traveller in London looking at Mumbai's panchang would see 01:25. Convert with the location'stz_offset_minutes, aslocalTimedoes. - `localhost` from an emulator. On the Android emulator your machine is
10.0.2.2, notlocalhost; on a physical device use your machine's LAN address. This only affects development - production points at your deployed backend.
Panchang is computed for a place and a civil date; sunrise depends on both. If your users can pick a city, store its coordinates and the UTC offset in force there (see birth time and time zones) and send those, not the device's location.
Questions
- Which AstroNode endpoints does the React Native example call?
- 1 endpoint: Panchang (
POST /v1/panchang). - Was the React Native code on this page actually run?
- The backend handler and the app's
fetchPanchang/localTimewere executed on Node 24 (samefetchAPI as React Native) against the in-memory API. The screen component is JSX and was not rendered on a device.