npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

astrologyapi

v1.0.1

Published

A Node.js SDK for accessing the astrologyapi.com endpoints

Readme

astrologyapi

A Node.js SDK for accessing the astrologyapi.com endpoints, supporting both JSON-based and PDF-based methods.

Table of Contents


Features

  • Vedic Astrology methods (e.g., birth details, astro details, horoscope PDFs, etc.)
  • Western Astrology methods (e.g., tropical planets, sun sign predictions, natal wheel charts, etc.)
  • PDF Support: Generate PDF reports (if your subscription/plan supports it)
  • Custom Requests: Call endpoints not explicitly defined in the SDK
  • Optional Language Parameter for localized results (if supported by your plan)

Installation

npm install astrologyapi

(Requires Node.js 12+)

Usage

  1. Initializing the SDK
// Import the SDK
const AstrologyAPI = require("astrologyapi");

// Create an instance with your credentials
const astrology = new AstrologyAPI({
  userId: "YOUR_USER_ID",    // numeric user ID
  apiKey: "YOUR_API_KEY",    // your API key
  apiType: "JSON",            // optional: "PDF" or "JSON" (defaults to "JSON")
  version: "v1"              // optional, defaults to "v1"
});

Key Parameters:

userId: Numeric user ID from your astrologyapi.com account.
apiKey: Your unique API key for authentication.
apiType (optional): "PDF" or "JSON". Defaults to "JSON".
version (optional): API version to use, defaults to "v1".

2. Vedic Methods

Each method returns a promise. Below are examples for commonly used endpoints. All methods accept an optional language parameter.

Birth Details

const params = {
  day: 1,
  month: 1,
  year: 2023,
  hour: 12,
  min: 24,
  lat: 19.07,
  lon: 72.87,
  tzone: 5.5
};

try {
  const birthDetails = await astrology.vedic.getBirthDetails(params, "en");
  console.log("Birth Details =>", birthDetails);
} catch (error) {
  console.error("Error fetching birth details:", error.message);
}

Astro Details

try {
  const astroDetails = await astrology.vedic.getAstroDetails(params, "en");
  console.log("Astro Details =>", astroDetails);
} catch (error) {
  console.error("Error fetching astro details:", error.message);
}

Planets

try {
  const planets = await astrology.vedic.getPlanets(params, "en");
  console.log("Planets =>", planets);
} catch (error) {
  console.error("Error fetching planets:", error.message);
}

Basic Horoscope PDF

If apiType is "PDF", you can generate PDF reports:

try {
  const pdfResponse = await astrology.vedic.getBasicHoroscopePDF({
    name: "Suraj Yadav",
    day: 1,
    month: 1,
    year: 2023,
    hour: 12,
    min: 24,
    lat: 19.07,
    lon: 72.87,
    tzone: 5.5,
    language:"en" // to know more about language options visit https://astrologyapi.com/docs/pdf-docs
  });
  console.log("Basic Horoscope PDF =>", pdfResponse);
} catch (error) {
  console.error("Error generating horoscope PDF:", error.message);
}

3. Western Methods

Similarly, for Western astrology endpoints:

Get Tropical Planets

try {
  const tropicalPlanets = await astrology.western.getTropicalPlanets(params, "en");
  console.log("Tropical Planets =>", tropicalPlanets);
} catch (error) {
  console.error("Error fetching tropical planets:", error.message);
}

Get Sun Sign Prediction (Daily)

try {
  // "aries" is an example zodiac name
  const dailyPrediction = await astrology.western.getSunSignPredictionDaily(
    {},       // your query parameters if any
    "en",     // language
    "aries"   // zodiacName
  );
  console.log("Daily Sun Sign Prediction =>", dailyPrediction);
} catch (error) {
  console.error("Error fetching sun sign prediction:", error.message);
}

Natal Wheel Chart

try {
  const natalWheel = await astrology.western.getNatalWheelChart(params);
  console.log("Natal Wheel Chart =>", natalWheel);
} catch (error) {
  console.error("Error fetching natal wheel chart:", error.message);
}

4. Custom Requests

If you need to call endpoints not yet provided as built-in methods, use the customRequest method:

try {
  const customEndpointResponse = await astrology.customRequest({
    method: "POST",
    endpoint: `sun_sign_prediction/daily/aries`,
    params: {
      // your request body or query params
         timezone:5.5,
    },
    language: "en"           // optional "Accept-Language" header
  });
  console.log("Custom Endpoint =>", customEndpointResponse);
} catch (error) {
  console.error("Error in custom request:", error.message);
}

Parameters:

method: Defaults to "POST".
endpoint: The API endpoint string (e.g., "some_new_endpoint").
params: Data for the request body (for POST) or query params (if using GET).
language: Optional, sets the "Accept-Language" header.
API Types: JSON vs. PDF
The SDK uses different base URLs for JSON and PDF:

If apiType is "JSON" (default), requests are routed to the JSON API. If apiType is "PDF", requests are routed to the PDF API, and certain parameters (like language) may be appended in the request body automatically.

const astrologyPDF = new AstrologyAPI({
  userId: "YOUR_USER_ID",
  apiKey: "YOUR_API_KEY",
  apiType: "PDF",   // or "JSON"
  version: "v1"
});

Error Handling

4xx/5xx Errors: The SDK will throw an error with the response body (if available).

No Response: Throws "No response received from the server.". Request Setup Error: Throws "Error in request setup: ...". Catch These Errors with try/catch to handle them in your application.

Example:

try {
  const result = await astrology.vedic.getBirthDetails(params, "en");
} catch (error) {
  console.error("API Call Error:", error.message);
}