swisseph-node
v1.0.1
Published
Modern N-API binding for Swiss Ephemeris — self-contained (vendored C sources), ships prebuilt binaries, bundle-friendly (base64-embedded fallback for serverless/bundler-only runtimes)
Maintainers
Readme
swisseph-node
Modern Node.js binding for the Swiss Ephemeris — N-API (stable ABI), compiles the upstream C sources unmodified.
Why another binding?
The classic swisseph npm package is NAN-based (must be rebuilt for every Node major), forks and patches the C code (hard to track upstream), and has been unmaintained for years. This package:
- Zero modifications to upstream C code —
binding.gypcompiles the pristine sources directly, so updating to a new Swiss Ephemeris release is just dropping in the new.c/.hfiles and rebuilding. - N-API / node-addon-api — one build works across Node major versions (≥16).
- Clean layered API — a faithful low-level mapping (
raw) plus a high-level chart/synastry/sky API returning structured data ready for chart rendering. - No bundled data — points at the Swiss Ephemeris files you already have (env var
SWISSEPH_EPHE_PATH), falling back to the built-in Moshier ephemeris when none are found.
Install / build
The Swiss Ephemeris C sources are vendored inside the package (vendor/, unmodified), so npm install swisseph-node just works. Prebuilt binaries ship for linux x64/arm64 and darwin x64/arm64 (N-API: one build works across Node majors ≥16); other platforms compile from vendor/ via npm rebuild swisseph-node.
Updating to a new Swiss Ephemeris release = dropping the new .c/.h files into vendor/ and bumping the version (CI regenerates prebuilds).
Bundle / serverless environments (esbuild, EdgeOne Cloud Functions, …)
Bundlers that inline everything into a single JS file leave no .node binary on disk. The loader (lib/raw.js) handles this: it falls back to base64-embedded binaries (lib/b64/<platform>.js, generated by scripts/gen-b64.js from the prebuilds), decodes one to os.tmpdir() on first use and loads it. Nothing to configure.
Ephemeris data files (semo_*.se1, sepl_*.se1, seas_*.se1) are resolved at runtime from:
setEphePath(path)— explicitSWISSEPH_EPHE_PATHenv var../swisseph-master/epherelative to the package
Without data files it silently falls back to the Moshier analytical ephemeris (planets only, slightly lower precision — Chiron/asteroids unavailable).
High-level API
const swe = require('swisseph-node');
const chart = swe.computeChart({
year: 2000, month: 1, day: 1, hour: 20, tz: 8, // local time + UTC offset
lat: 39.9042, lon: 116.4074, // Beijing
houseSystem: 'P', // Placidus
});
// chart.planets -> [{key:'sun', lon, sign:'capricorn', house, retrograde, speed, degreeInSign, ...}]
// chart.houses -> {cusps[12], ascendant, midheaven, vertex, cuspsFormatted}
// chart.aspects -> [{a:'sun', b:'moon', aspect:{key:'square', orbDelta:1.2, ...}}]
// chart.balances-> {elements:{fire:3,...}, modes:{...}}
const syn = swe.computeSynastry(birthA, birthB);
// syn.crossAspects, syn.aHousesOfB, syn.bHousesOfA
const sky = swe.computeSky({ year: 2026, month: 10, day: 24, hour: 21, tz: 8, lat: 39.9, lon: 116.4 });
// sky.bodies -> [{key:'moon', azimuth, altitude, illumination}]
// sky.stars -> bright-star catalog with horizontal coordinatesLow-level API (raw)
One-to-one with the C API (swephexp.h): version, setEphePath, julDay, revJul,
utcToJd, utcTimeZone, deltat, calcUt, houses, getPlanetName, ayanamsaUt,
azAlt, phenoUt, solEclipseWhenLoc, lunOccultWhenLoc, setTopo, setSidMode, close.
Test
npm testVerified against reference values generated by the upstream swetest binary (sub-milliarcsecond agreement).
License
AGPL-3.0 (as Swiss Ephemeris). Commercial licensing for the underlying ephemeris may be obtained from Astrodienst.
