# sweph for Node.js vs a hosted astrology API

> sweph wraps the Swiss Ephemeris C library as a Node.js native add-on: every function of the C API, typed for TypeScript, with its version number tied to the upstream release. For a Node backend it is the direct route to in-process positions. Like the C library, it stops at astronomy - houses and ayanamsas yes, dashas and panchang no.

Source: https://astronode.dev/compare/self-hosting/sweph-node · Facts checked: 2026-12-05

## When self-hosting sweph is the better choice

- Your backend is Node.js and you want positions in-process. A native call avoids a network hop on every chart, which matters for search loops (next ingress, next station) and batch jobs.
- You want the full C API, not a subset: fixed stars, eclipses, heliocentric and topocentric frames, every house method and sidereal mode. The README claims 100% coverage, and the official Swiss Ephemeris programmer's manual applies directly.
- You want to know exactly which upstream you run. Versions are locked to Swiss Ephemeris releases - 2.10.4 is Swiss Ephemeris 2.10.04 - and the latest release is from November 2026.
- TypeScript in the editor. Declarations and inline documentation ship with the package, so each function's arguments show up as you type.

## Side by side

|  | sweph | AstroNode API |
| --- | --- | --- |
| Language / runtime | Node.js only - a native C/C++ add-on, not for browsers ([source](https://github.com/timotejroiko/sweph)) | Any language: HTTPS + JSON, OpenAPI 3.1 spec ([details](https://astronode.dev/guides/openapi-typed-client)) |
| Install and native build | Prebuilt binaries; otherwise a native build with a C toolchain ([source](https://github.com/timotejroiko/sweph)) | Nothing to compile; an API key and an HTTP client ([details](https://astronode.dev/quickstart/curl)) |
| Planet positions | Yes - the whole Swiss Ephemeris API ([source](https://github.com/timotejroiko/sweph)) | Sidereal and tropical, from Swiss Ephemeris data files ([details](https://astronode.dev/capabilities/vedic)) |
| House systems | Yes - the C library's house functions ([source](https://github.com/timotejroiko/sweph)) | Whole-sign (Vedic), Placidus (KP), five Western systems ([details](https://astronode.dev/guides/house-systems)) |
| Sidereal / ayanamsa | Yes - set_sid_mode(), but the setting is process-wide ([source](https://github.com/timotejroiko/sweph)) | Fixed per tradition: Lahiri, KP-Newcomb, tropical ([details](https://astronode.dev/guides/ayanamsa)) |
| Dashas | Not documented | Vimshottari, Yogini, Char ([details](https://astronode.dev/guides/vimshottari-dasha-calculation)) |
| Divisional charts (vargas) | Not documented | 16 vargas in one call, plus D150 ([details](https://astronode.dev/guides/divisional-chart-calculation)) |
| KP sub-lords | Not documented | Cuspal sub-lord chain, significators, horary 1-249 ([details](https://astronode.dev/capabilities/kp)) |
| Panchang | Not documented | Tithi, nakshatra, yoga, karana, sunrise, muhurta windows ([details](https://astronode.dev/guides/panchang-sunrise-conventions)) |
| Yogas | Not documented | 55 classical yogas with reasons ([details](https://astronode.dev/capabilities/vedic)) |
| Kundli matching | Not documented | Ashtakoot, Dashakoot, Porutham, batch scoring ([details](https://astronode.dev/capabilities/compatibility)) |
| Ephemeris data you ship | None included; download .se1 files and call set_ephe_path() ([source](https://github.com/timotejroiko/sweph)) | None on your side |
| Time zones and historical offsets | Not handled (same as the C library); pass UT ([source](https://www.astro.com/swisseph/swephprg.htm)) | You send the offset in force at birth; no zone-name lookup ([details](https://astronode.dev/guides/birth-time-and-time-zones)) |
| Maintenance signal | Active: 2.10.4 on npm, published 27 November 2026 ([source](https://registry.npmjs.org/sweph)) | Hosted; changes published in the changelog ([details](https://astronode.dev/changelog)) |
| Stated accuracy | Not documented | Measured in CI vs NASA JPL Horizons: Moon 3.1″, planets ≤ 0.5″ (1900-2050) ([details](https://astronode.dev/)) |

| More from their docs |  |
| --- | --- |
| Upstream version | Matches Swiss Ephemeris 2.10.04 ([source](https://github.com/timotejroiko/sweph)) |
| Threads | Settings are shared across worker_threads ([source](https://github.com/timotejroiko/sweph)) |
| TypeScript | Typings and ESM exports included ([source](https://github.com/timotejroiko/sweph)) |

## What you still build yourself

- The Vedic layer: nakshatras, dasha periods, sixteen vargas, the KP sub-lord table, tithi/yoga/karana with end times, yogas and matching. sweph gives you the longitudes those rules start from.
- Per-request conventions. set_sid_mode() and set_ephe_path() are process-wide, so a server that mixes Lahiri and Krishnamurti requests must serialise calls or split the work across child processes.
- Ephemeris provisioning: download the .se1 files you need from the Swiss Ephemeris repository and ship them with each deployment.
- Local time to UT with the historical offset for the birthplace.
- A separate path for browsers and edge runtimes, where a native add-on cannot load.

## Running it in production

- Native binaries. Prebuilds cover the supported platforms; anywhere else, npm install falls back to a source build that needs python, make and gcc on Linux, Xcode on macOS or the Visual C++ build tools on Windows. Check your CI image and deploy target before relying on the prebuild.
- Data files. Each main file covers 600 years (sepl_18.se1 is 1800-2400); planets, Moon and asteroids are separate files. As with the C library, a wrong path means the engine falls back to its lower-precision built-in model rather than failing.
- Concurrency. worker_threads share the C library's global settings; true isolation needs child_process.
- Upstream changes arrive as new sweph versions that match Swiss Ephemeris releases - a dependency bump and a native rebuild on your side.
- Whatever the library, the birth input is a local clock time, and turning it into UT needs the offset that was in force on that date - our [UTC offset finder](https://astronode.dev/tools/utc-offset-finder) and the [time-zone guide](https://astronode.dev/guides/birth-time-and-time-zones) cover the traps.

## Accuracy

sweph's README states no accuracy figure of its own. It runs Swiss Ephemeris 2.10.04, so precision is whatever that engine and the data files you install deliver - see the Swiss Ephemeris page for the upstream figures. AstroNode's CI compares positions with NASA JPL Horizons and measured the Moon within 3.1″ and every planet within 0.5″ from 1900 to 2050.

## Where an API saves work

- The Vedic rules on top of the positions - three dasha systems, sixteen vargas, KP sub-lords, panchang, 55 yogas and matching - as endpoints.
- No native build matrix and no .se1 directory in every container.
- Per-request conventions without process-wide state: each call carries its own tradition, so Lahiri and KP requests never interfere.
- Works from browsers, React Native and edge runtimes, where a Node add-on cannot run.

## Questions

**What do I need to install to use sweph?**

sweph: Prebuilt binaries; otherwise a native build with a C toolchain. AstroNode API: Nothing to compile; an API key and an HTTP client. Checked 2026-12-05.

**Does sweph calculate dashas?**

sweph: Not documented. AstroNode API: Vimshottari, Yogini, Char. Checked 2026-12-05.

**Does sweph support KP sub-lords?**

sweph: Not documented. AstroNode API: Cuspal sub-lord chain, significators, horary 1-249. Checked 2026-12-05.

**Does sweph do kundli matching?**

sweph: Not documented. AstroNode API: Ashtakoot, Dashakoot, Porutham, batch scoring. Checked 2026-12-05.

**Does sweph handle time zones and historical offsets?**

sweph: Not handled (same as the C library); pass UT. AstroNode API: You send the offset in force at birth; no zone-name lookup. Checked 2026-12-05.
