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

@riank718/nasa-sdk

v1.0.3

Published

A TypeScript SDK for NASA's public APIs with type-safe access using Zod.

Readme

Star Wars Space GIF

🚀 NASA APOD SDK

A production-grade, TypeScript-first SDK for the NASA Astronomy Picture of the Day (APOD) API. Engineered for reliability, performance, and developer experience.

Badges

NPM Version MIT License NPM Downloads TypeScript


🔑 Authentication & API Keys

This SDK makes it simple to integrate NASA's APIs. While some endpoints allow public access, it is highly recommended to obtain a free API key to avoid strict rate limiting.

  • Get your Key: Register at api.nasa.gov (Free and easy).
  • Rate Limits: API keys are limited to 1,000 requests per hour.
  • Efficiency: We have implemented strict client-side validation using Zod. This prevents malformed requests from being sent to NASA, saving you from wasting your hourly request quota.

✨ Features

  • ✅ Fetch Today’s APOD
  • 🎲 Fetch Random APODs
  • 📅 Fetch APOD by date or date range
  • 🔁 Automatic retry with configurable backoff
  • 🛑 AbortSignal support (React-friendly)
  • 🧪 Fully tested with Vitest
  • 📦 Dual build output (ESM + CJS)
  • 🔒 Runtime response validation using Zod
  • 💯 TypeScript-first API

📦 Installation

Install the SDK via npm:

npm install @riank718/nasa-sdk

🚀 Usage/Examples

import { NasaSDK } from '@riank718/nasa-sdk';

const nasa = new NasaSDK({
  apiKey: 'YOUR_NASA_API_KEY', // Defaults to 'DEMO_KEY'
  retries: 3,                 // Optional: Default 3
  retryDelayMs: 500           // Optional: Default 500ms
});

// Using the SDK
async function fetchSpaceData() {
  try {
    const apod = await nasa.getApod('2025-12-25');
    console.log(apod.title, apod.url);
  } catch (error) {
    console.error("SDK Error:", error.message);
  }
}

🧪 Prevent runtime crashes (best practice)

Optional but recommended:

const apiKey = import.meta.env.VITE_NASA_API_KEY;

if (!apiKey) {
  throw new Error('Missing VITE_NASA_API_KEY');
}

export const nasa = new NasaSDK({ apiKey });

⚛️ React Example (with AbortSignal)

This example demonstrates safe data fetching in React using AbortController to prevent memory leaks and race conditions.

import { useEffect, useState } from 'react';
import { nasa } from './api/nasa'; // Initialized SDK instance

function ApodComponent({ selectedDate }: { selectedDate: string }) {
  const [data, setData] = useState<any>(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const controller = new AbortController();

    setLoading(true);
    nasa
      .getApod(selectedDate, controller.signal)
      .then(setData)
      .catch(err => {
        if (!(err instanceof DOMException)) {
          setError(err.message);
        }
      })
      .finally(() => setLoading(false));

    return () => controller.abort();
  }, [selectedDate]);

  if (loading) return <div>Loading...</div>;
  if (error) return <div style={{ color: 'red' }}>{error}</div>;

  return <h2>{data.title}</h2>;
}

🛠️ API Reference

Get APOD for a specific date

nasa.getApod(date?: string, signal?: AbortSignal)

🏗️ Architecture

The SDK acts as a defensive proxy

  1. Validation Layer: Catches bad dates/parameters locally.
  2. Retry Engine: Handles transient 500 errors automatically.
  3. Schema Layer: Ensures NASA's response matches our TypeScript interfaces exactly.

🧪 Development

Run Locally

git clone [https://github.com/anand-1809/nasa-sdk](https://github.com/anand-1809/nasa-sdk)
cd nasa-sdk
npm install

🔐 Environment Variables (Frontend Apps)

If you’re using this SDK in Vite / React:

VITE_NASA_API_KEY=your_api_key_here

Usage

const nasa = new NasaSDK({
  apiKey: import.meta.env.VITE_NASA_API_KEY
});

🧪 Running Tests

npm run test

🧑‍💻 Tech Stack

  • Language: TypeScript
  • Validation: Zod
  • Testing: Vitest
  • Bundler: tsup
  • Runtime: Fetch API

⭐ Contributing

PRs and suggestions are welcome. If you find this useful, consider starring the repo ⭐