๐ Lightweight wrapper for NASA's API library.
Celestial Bodies is a lightweight wrapper for NASA's API library.
๐ System Requirements | :waxing_crescent_moon: Installation | :crescent_moon: Usage | :moon: Contributing | :full_moon: Credits
At its core, Celestial Bodies relies on Node.js and NPM for its core functionality.
- Node ^14
- NPM ^6
npm install celestial-bodies
Require the package to access the preconfigured API functions.
const celestial = require('celestial-bodies');
Each API function takes a payload
object which includes the necessary data to process the request.
The key
value is required for all calls. You can leave it as DEMO_KEY
and the functions will still work as intended, but the API call limitations will be stricter. Otherwise, request a free API code from NASA's website and use that as the key value (recommended).
Currently, Celestial Bodies has built-in functionality for:
Astronomy Image of the Day
Near Earth Orbit Web Service
Space Weather Database of Notifications, Knowledge, and Information (DONKI)
Earth - Landsat Imagery
The apod()
function is used to leverage the Astronomy Picture of the Day API.
The date
parameter specifies the date for the returned image. Date will default to today
if empty, and is expecting the value to be formatted as YYYY-MM-DD
.
You can also use start_date
and end_date
parameters to get a range of dates and their associated images. End date is today
by default.
The count
parameter is available for querying a number of random images. If you use count
you cannot use any of the other three date parameters.
If the picture of the day is a video, you can use the thumbs
parameter to specify whether you want it to return a video thumbnail or not. This parameter defaults to false.
// get results for 04/20/2021 //
const payload = {
key: 'DEMO_KEY',
date: '2021-04-20',
};
celestial.apod(payload, pictureOfTheDay => {
return pictureOfTheDay;
});
The asteroids()
function provides access to NASA's Near Earth Object Web Service. This call has three separate modes - feed
, lookup
, and browse
.
For this mode, provide your key
in the request along with the start_date
and end_date
for the range of dates you would like results for. This range can be no more than seven days.
const payload = {
end_date: '2021-01-01',
key: 'DEMO_KEY',
start_date: '2021-01-02',
type: 'feed'
};
celestial.apod(payload, asteroid => {
return asteroid;
});
In addition to your key
, you need to provide the request with the asteroid_id
, which is the id of the asteroid you're looking up.
const payload = {
asteroid_id: 3471590,
key: 'DEMO_KEY',
type: 'lookup'
};
celestial.apod(payload, asteroid => {
return asteroid;
});
This mode doesn't require any parameters aside from the api key.
These mode values are passed in through type
payload parameter.
const payload = {
key: 'DEMO_KEY',
type: 'browse'
};
celestial.apod(payload, asteroid => {
return asteroid;
});
The donki()
function provides access to the Space Weather Database of Notifications, Knowledge, and Information (DONKI). This API is particularly useful for space weather forecasters, scientists, and the general space science community.
The API consists of a variety of components, each providing access to different data.
Coronal Mass Ejections (CMEs) are large expulsions of plasma and magnetic field from the Sun's corona. This API provides data for specific CME events in a specified time period.
The start_date
and end_date
parameters are optional, and if omitted from the payload the request will default to pulling the last 30 days worth of data.
const payload = {
start_date: '2021-01-01', // optional //
end_date: '2021-01-02', // optional //
key: 'DEMO_KEY',
type: 'cme'
};
celestial.donki(payload, cmeResponse => {
return cmeResponse;
});
The earth()
function is designed to give you an easy to use taste of what Landsat imagery data can provide. There are two different types for this API - imagery
and assets
- which serve slightly different purposes.
This endpoint retrieves the Landsat 8 image for the supplied location and date.
This endpoint retrieves the date-times and asset names for closest available imagery for a supplied location and date.
Contributions are welcome - feel free to submit a pull request and it will be reviewed promptly.