I run Astrology Geeks, a UK-based site with free chart calculators. The method we publish is straightforward: chart math comes from Swiss Ephemeris. The calculator converts a birth moment to UTC, derives a Julian date, calculates positions along the zodiac, and assigns those placements to houses.

What the site does not publish is the Node.js package name behind that step, and I am not going to invent one. This article is a practical guide to the well-known public packages that wrap the Swiss Ephemeris C library for Node.js. The code below is taken from the public API of the sweph package, which I checked on npm and in its TypeScript typings. It is not a copy of our server source.

What the library is for

Swiss Ephemeris is a C library from Astrodienst. It answers astronomical questions: where is this body at this instant, what are the house cusps for this time and place, and how fast is the body moving? It does not write an interpretation, and it does not, by itself, return a list of aspects. Those are built from the longitudes it gives you.

That split matters for a product. On Astrology Geeks, calculated data (degrees, signs, cusps, retrograde status, aspects, Moon phase) sits next to the written text, so a reader can see what a paragraph is talking about. The astronomy can be checked. The wording is a separate layer.

Three Node packages, and why the examples use sweph

There is no single official “the” npm package. On 3 December 2026, these three were the ones you will actually find:

  • sweph, version 2.10.4, described as Swiss Ephemeris 2.10.04. It is a native N-API binding with close coverage of the C API: utc_to_jd, calc_ut, houses, set_ephe_path. Ephemeris files are not bundled. Current releases from 2.10.1 onward are licensed under AGPL-3.0, with LGPL available if you hold a professional Swiss Ephemeris licence, and 2.10.0 still offered under GPL.
  • swisseph, version 0.5.17, published in January 2022. This is the older binding many tutorials still show. Its examples use callback-style swe_julday and swe_calc_ut.
  • @swisseph/node, version 1.6.0. This one exposes a higher-level TypeScript API (dateToJulianDay, calculatePosition, calculateHouses) and bundles ephemeris files so you can start without a separate download.

I am writing against sweph because its function names match the official C documentation, which is what most astronomy-and-astrology references discuss. If your host cannot load a native add-on, a WebAssembly build is a different discussion; sweph itself will not run in the browser.

Read the licence of whichever package you pick before you ship a public site. I am not stating how Astrology Geeks is licensed.

Install the package and point it at ephemeris files

npm install sweph 

For the high-precision Swiss files, download the planet, Moon and (if you need them) asteroid files, put them in a folder, and tell the library where they are. The typings show this as the first call you make:

// Public API example from the sweph typings, not our source. const { utc_to_jd, calc_ut, houses_ex2, split_deg, set_ephe_path, constants, } = require("sweph"); set_ephe_path("./ephemeris"); 

Each main file covers 600 years. A sepl_18.se1 file, for example, covers the planets from 1800 to 2400. If you skip this step and still request the Swiss files with SEFLG_SWIEPH, the call can fail or fall back. Always inspect the returned flag and error.

First convert the birth moment to UTC, then to a Julian day

The input to Swiss Ephemeris is not “3:15pm in Manchester”. It is a continuous time value. Our published pipeline starts by converting the local birth moment to UTC, then deriving a Julian date. The library will not look up Europe/London for you. You have to resolve the time zone, including historical offsets and daylight-saving rules, before you call it.

sweph then gives you both time scales in one call. Ephemeris/terrestrial time is what calc expects. Universal time is what calc_ut and the house functions expect:

// 15 June 1990, 12:00:00 UTC, Gregorian calendar. // Public API example from the sweph typings. const utc = utc_to_jd(1990, 6, 15, 12, 0, 0, constants.SE_GREG_CAL); if (utc.flag !== constants.OK) { throw new Error(utc.error); } const [jdEt, jdUt] = utc.data; 

julday also exists if you already have a decimal hour, but utc_to_jd is the function the typings lead with when the input is a UTC calendar date.

calc_ut: positions, speed, and retrograde

calc_ut takes a Julian day in universal time, a body ID, and a flag bitmask. The usual starting flags are “use the Swiss files” and “also return daily speeds”:

const flags = constants.SEFLG_SWIEPH | constants.SEFLG_SPEED; const sun = calc_ut(jdUt, constants.SE_SUN, flags); if (sun.flag === constants.ERR) { throw new Error(sun.error); } // If the returned flags do not match the flags you asked for, // the library may have fallen back. Read sun.error before trusting sun.data. const [longitude, latitude, distanceAu, lonSpeed] = sun.data; const retrograde = lonSpeed < 0; 

With the default flags, data[0] is ecliptic longitude in degrees, data[1] is latitude, data[2] is distance in astronomical units, and data[3] is the daily speed in longitude. A negative speed is the usual test for retrograde: the body appears to be moving backwards from Earth’s point of view. That is also how our calculator page describes retrograde status.

The typings also include calc, which is the same calculation from ephemeris time. Use one or the other consistently. Do not pass a UT Julian day to calc, or an ET Julian day to calc_ut, and expect the same second of time.

Body IDs are stable integers. These are the ones you need for a typical Western natal chart:

const BODIES = { Sun: constants.SE_SUN, // 0 Moon: constants.SE_MOON, // 1 Mercury: constants.SE_MERCURY, // 2 Venus: constants.SE_VENUS, // 3 Mars: constants.SE_MARS, // 4 Jupiter: constants.SE_JUPITER, // 5 Saturn: constants.SE_SATURN, // 6 Uranus: constants.SE_URANUS, // 7 Neptune: constants.SE_NEPTUNE, // 8 Pluto: constants.SE_PLUTO, // 9 meanNode: constants.SE_MEAN_NODE, // 10 trueNode: constants.SE_TRUE_NODE, // 11 meanApogee: constants.SE_MEAN_APOG, // 12, often used for mean Black Moon Lilith oscApogee: constants.SE_OSCU_APOG, // 13, osculating Lilith Chiron: constants.SE_CHIRON, // 15 Pholus: constants.SE_PHOLUS, // 16 Ceres: constants.SE_CERES, // 17 Pallas: constants.SE_PALLAS, // 18 Juno: constants.SE_JUNO, // 19 Vesta: constants.SE_VESTA, // 20 }; 

Our birth chart calculator lists the Sun through Pluto, the North and South Nodes, Chiron, Ceres, Juno, Pallas, Vesta, Pholus, Black Moon Lilith, White Moon Selena, the Vertex and the Part of Fortune, plus the chart angles. The site does not say whether the node is the mean or true node, or which Lilith is used, so I am not going to guess. The South Node, as the calculator page itself says, is opposite the North Node by 180 degrees, so you do not need a second ephemeris call for it. The Vertex comes back with the house calculation, below. The Part of Fortune and White Moon Selena are calculated points, not standard planet IDs, and their exact formulae are not published on the site.

To turn a longitude such as 130.234° into a sign and a degree within that sign, the package exposes split_deg. Its own typings example, using SE_SPLIT_DEG_ZODIACAL, returns 10 degrees in sign number 4, which is Leo if you count Aries as zero. That matches the usual rule: twelve 30-degree sign sectors around a 360-degree circle, which is also how our calculator page describes the wheel.

Default calculations are tropical. If you need a sidereal zodiac, the flag is SEFLG_SIDEREAL, and you also have to set an ayanamsa with set_sid_mode. Astrology Geeks describes its written output as using Western tropical placements, so a tropical calculation is the one that will compare cleanly with our wheel.

houses: cusps, angles, and the letter codes

House cusps need the Julian day in universal time, the geographic latitude and longitude, and a one-letter house system:

// London: 51.5074 N, 0.1278 W. "P" is Placidus. // Public API example from the sweph typings. const result = houses_ex2(jdUt, 0, 51.5074, -0.1278, "P"); if (result.flag !== constants.OK) { console.log(result.error); } const cusps = result.data.houses; // twelve longitudes, index 0 is house 1 const [ascendant, midheaven, armc, vertex] = result.data.points; 

The simpler houses function returns the same cusps and points without the speed arrays. The typings example uses houses_ex2, with 0 for the extra flags.

Those letters are part of the public Swiss Ephemeris API. The ones our calculator actually offers in its Advanced control, with Placidus as the default, are:

const HOUSE_SYSTEMS = { P: "Placidus (default)", K: "Koch", W: "Whole Sign", E: "Equal House", M: "Morinus House", O: "Porphyrius", R: "Regiomontanus", C: "Campanus", }; 

A house system changes house assignments, not planetary longitudes. Mars at 14° Leo stays at 14° Leo. Only its house can move. Our calculator page says so, and it is the first thing to check if two programs disagree.

Whole Sign has an extra quirk on our site, and it is worth knowing about if you implement that system yourself. When Whole Sign is selected, the houses follow whole signs, but the Ascendant and Midheaven shown are still the Placidus angles. The Ascendant degree therefore does not sit on the first house cusp. That is easy to mistake for a bug if you do not document it.

To put a planet in a house, do not just walk the cusp list and hope, especially in time-based systems such as Placidus. sweph exposes house_pos, which also takes the object’s ecliptic latitude, the obliquity of the ecliptic, and the right ascension of the Midheaven (armc from houses). The return value is a house number with a fraction; Math.floor gives the house.

In quadrant systems such as Placidus, the Descendant and Imum Coeli, which our results also show, are the points opposite the Ascendant and Midheaven.

What you still have to write yourself

Aspects are a good example. The library gives you longitudes. An aspect is an angular separation compared with a set of orbs: 0° conjunction, 60° sextile, 90° square, 120° trine, 180° opposition, and any minor aspects you choose to include. Our calculator lists those major aspects and uses configured orbs. The site does not publish the orb values, and the public package does not invent them for you.

The same is true of chart patterns, Moon phase (the angular relationship of the Sun and Moon), and any interpretive text. Keep that code downstream of the ephemeris, and keep the numbers visible. It is the same rule we use when a language model writes a chart reading: the chat should start from calculated positions, not from a placement the model has made up.

A few Node.js details that bite people

sweph is a C add-on. It will not run in the browser, and it needs a host that can load native modules, or a prebuilt binary for that platform. On Astrology Geeks, the calculator form is a Next.js client; the published calculation happens after the form is submitted, which is the right side of the line for a library like this.

Settings such as set_ephe_path and set_sid_mode are process-wide. The sweph documentation is explicit: the underlying C library is single-threaded in that sense. Worker threads will see the same path and the same sidereal mode. If you need isolation, use a child process.

Check every flag. A missing file, an unsupported date, or a bad body ID should be an error you handle, not a quiet NaN on a chart wheel.

And test at least one known chart against another trusted Swiss Ephemeris program, with the same house system, the same zodiac, and the same UTC instant. If the longitudes disagree by more than a tiny fraction of a degree, the bug is almost always in the time conversion, not in calc_ut.

A short checklist

  1. Resolve local birth time to UTC yourself, then call utc_to_jd.
  2. Call set_ephe_path and request SEFLG_SWIEPH if you want the Swiss files.
  3. Use calc_ut for bodies, and treat negative longitude speed as retrograde.
  4. Use houses with the official letter for the chosen system.
  5. Compute aspects, Part of Fortune, and copy in your own code.
  6. Compare the longitudes with a known chart before you trust the page.

That is the whole job, in outline: a UTC instant, a Julian day, calc_ut, houses, and then everything else you choose to build on top.

Try it on a live chart

I run Astrology Geeks, and the method above is the one we publish for our calculators. If you want to compare a result from this code against a live wheel, placement tables and aspect list, open our free birth chart calculator.