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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mariolazzari/nasa-api

v0.1.1

Published

NASA public REST API client

Downloads

13

Readme

Nasa Open API client


This package is a TypeScript based wrapper around the public NASA REST APIs.

Prerequisites

In order to use this package, you need an api key: You can read more on how to obtain the API key on this page.

This package requires NodeJS (version 18 or later) and a node package manager (Npm, Yarn, Pnpm or Bun).

To make sure you have them available on your machine, try running the following command.

$ npm -v && node -v
v10.1.0
v18.18.0

Gettting started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.


Installation

BEFORE YOU INSTALL: please read the prerequisites.

Start with cloning this repo on your local machine:

$ git clone https://github.com/mariolazzari/nasa-api.git
$ cd nasa

To install and set up the library, run:

npm install @mariolazzari/nasa-api

Usage

Import package

import { Nasa } from "@mariolazzari/nasa-api"

Watch mode

npm test

Unit testing

npm test

Bulding new version

npm build

This task will create a distribution version of the project inside your local dist/ folder


Nasa class

Nasa class content handles all the requests and the responses to the three main Rijks museum REST APIs.

Constructor

In order to initialize Nasa client:

const nasa = new Nasa(NASA_API_KEY)

Constructor parameters

| Parameter | Type | Required | Default | | --------- | ------ | :------: | ------- | | apiKey | string | Yes | |

Methods

Nasa client includes the following three methods:

apodDate

Description

This asynchronous method handles GET /planetary/apod REST API, in order to return the astronomical picture of the day for selected day (current day by default).

Prototype

async apodDate(date: Date = new Date()): Promise<Result<Apod>> 

Sample code

const date = new Date(2023, 2, 28);
const apod: Result<Apod> = await nasa.apodDate(date);

apodDates

Description

This asynchronous method handles GET /planetary/apod REST API, in order to return the astronomical pictures of the day for selected date range.

Prototype

async apodDates(from: Date = new Date(), to: Date = new Date()): Promise<Result<Apod[]>> 

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const apods: Result<Apod[]> = await nasa.apodDates(from, to);

apodRandom

Description

This asynchronous method handles GET /planetary/apod REST API, in order to return n random astronomical pictures of the day (10 pictures by default).

Prototype

async apodRandom(n:number = 10): Promise<Result<Apod[]>> 

Sample code

const apods: Result<Apod[]> = await nasa.apodRandom(10);

neoFeed

Description

This asynchronous method handles GET /neo/rest/v1/feed REST API, in order to return the near Earth objects for selected dates range.

Prototype

async neoFeed(from: Date, to: Date): Promise<Result<NeoResponse>> 

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const neos: Result<NeoResponse> = await nasa.neoFeed(from, to);

neoLookup

Description

This asynchronous method handles GET /neo/rest/v1/neo/:id REST API, in order to return the near Earth objects for selected asteroid ID, including its orbital data.

Prototype

async neolookup(asteroidId:number): Promise<Result<Neo & Link>> 

Sample code

const asteroidId = 3542519
const neo: Result<Neo & Link> = await nasa.neoLookup(asteroidId);

donkiCme

Description

This asynchronous method handles GET /DONKI/CME REST API, in order to return the coronal mass ejection (CME) for selected dates range.

Prototype

async donkiCme(from: Date, to: Date): Promise<Result<CoronalMassEjection[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const cme: Result<CoronalMassEjection[]> = await nasa.donkiCme(from, to);

donkiCmeAnalysis

Description

This asynchronous method handles GET /DONKI/CMEAnalysis REST API, in order to return the coronal mass ejection (CME) analysis for selected dates range.

Prototype

async donkiCme(from: Date, to: Date, mostAccurateOnly: boolean, completeEntryOnly: boolean, speed:number ): Promise<Result<CoronalMassEjectionAnalysis[]>> 

Method parameters

| Parameter | Type | Required | Default | | ----------------- | ------- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today | | mostAccurateOnly | boolean | No | true | | completeEntryOnly | boolean | No | true | | speed | number | No | 0 |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const cmeAnalysis: Result<CoronalMassEjectionAnalysis>[] = await nasa.donkiCmeAnalysis(from, to);

donkiGst

Description

This asynchronous method handles GET /DONKI/GST REST API, in order to return the Geomagnetic Storm (GST) for selected dates range.

Prototype

async donkiGst(from: Date, to: Date ): Promise<Result<GeomagneticStorm[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const gst: Result<GeomagneticStorm[]> = await nasa.donkiCme(from, to);

donkiIps

Description

This asynchronous method handles GET /DONKI/IPS REST API, in order to return the Interplanetary Shock (IPS) for selected dates range.

Prototype

async donkiIps(from: Date, to: Date ): Promise<Result<InterplanetaryShock[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const ips: Result<InterplanetaryShock[]> = await nasa.donkiIps(from, to);

donkiFlr

Description

This asynchronous method handles GET /DONKI/FLR REST API, in order to return the Solar Flare (FLR) for selected dates range.

Prototype

async donkiFlr(from: Date, to: Date ): Promise<Result<SolarFlare[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const ips: Result<SolarFlare[]> = await nasa.donkiIps(from, to);

donkiSep

Description

This asynchronous method handles GET /DONKI/SEP REST API, in order to return the Solar Energetic Particle (SEP) for selected dates range.

Prototype

async donkiSep(from: Date, to: Date ): Promise<Result<SolarEnergeticParticle[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<SolarEnergeticParticle[]> = await nasa.donkiSep(from, to);

donkiMpc

Description

This asynchronous method handles GET /DONKI/MPC REST API, in order to return the Magnetopause Crossing (MPC) for selected dates range.

Prototype

async donkiMpc(from: Date, to: Date ): Promise<Result<MagnetopauseCrossing[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<MagnetopauseCrossing[]> = await nasa.donkiMpc(from, to);

donkiRbe

Description

This asynchronous method handles GET /DONKI/RBE REST API, in order to return the Radiation Belt Enhancement (RBE) for selected dates range.

Prototype

async donkiRbe(from: Date, to: Date ): Promise<Result<RadiationBeltEnhancement[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<RadiationBeltEnhancement> = await nasa.donkiRbe(from, to);

donkiHss

Description

This asynchronous method handles GET /DONKI/HSS REST API, in order to return the Hight Speed Stream (HSS) for selected dates range.

Prototype

async donkiRbe(from: Date, to: Date ): Promise<Result<HightSpeedStream[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<HightSpeedStream[]> = await nasa.donkiHss(from, to);

donkiWsa

Description

This asynchronous method handles GET /DONKI/WSAEnlilSimulations REST API, in order to return the WSA+EnlilSimulation for selected dates range.

Prototype

async donkiWsa(from: Date, to: Date ): Promise<Result<WsaEnlilSimulation[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<WsaEnlilSimulation[]> = await nasa.donkiWsa(from, to);

donkiNotifications

Description

This asynchronous method handles GET /DONKI/notifications REST API, in order to return the Notifications for selected dates range.

Prototype

async donkiNotifications(from: Date, to: Date ): Promise<Result<Notification[]>> 

Method parameters

| Parameter | Type | Required | Default | | --------- | ---------------- | :------: | -------------- | | from | Date | No | 30 days before | | to | Date | No | today | | type | NotificationType | no | all |

Sample code

const from = new Date(2023, 2, 21);
const to = new Date(2023, 2, 8);
const sep: Result<Notification[]> = await nasa.donkiNotifications(from, to);

Authors

  • Mario Lazzari - Initial work

Links