https://github.com/dashutosh04/nasa-apod-fetcher
NASA APOD Data Fetcher is a Node.js library that provides a simple way to access and retrieve data from NASA's Astronomy Picture of the Day (APOD) API. It allows you to easily fetch information about the daily featured image, including its copyright, date, explanation, media type, and more.
https://github.com/dashutosh04/nasa-apod-fetcher
apod nasa nasa-api nasa-apod nasa-apod-api
Last synced: 11 months ago
JSON representation
NASA APOD Data Fetcher is a Node.js library that provides a simple way to access and retrieve data from NASA's Astronomy Picture of the Day (APOD) API. It allows you to easily fetch information about the daily featured image, including its copyright, date, explanation, media type, and more.
- Host: GitHub
- URL: https://github.com/dashutosh04/nasa-apod-fetcher
- Owner: dashutosh04
- License: mit
- Created: 2024-09-10T20:41:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-10T21:44:28.000Z (almost 2 years ago)
- Last Synced: 2025-01-29T13:14:09.053Z (over 1 year ago)
- Topics: apod, nasa, nasa-api, nasa-apod, nasa-apod-api
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 🚀 NASA APOD Data Fetcher
### 📝 Description
This `Node.js` project provides a set of functions to fetch data from *NASA's Astronomy Picture of the Day (APOD)* API. It allows you to easily retrieve information about the daily featured image, including its copyright, date, explanation, media type, and more.
### 💫 Features
- Fetches complete APOD data using your NASA API key.
- Extracts specific properties like copyright, date, explanation, HD URL, media type, service version, title, and image URL.
- Handles errors gracefully by logging them and returning default values for missing data.
- Improved Security: Explicitly checks for missing API keys and throws informative errors.
### 💻 Installation
1. **Clone the repository:**
```bash
git clone https://github.com/dashutosh04/nasa-apod.git
```
2. **Install dependencies:**
```bash
npm install
```
3. **Set NASA API Key:**
You'll need a NASA API key. Obtain one from https://api.nasa.gov/ and set it as an environment variable named `NASA_API_KEY`.
### ✒️ Usage
#### Import the functions:
```js
import {
getData,
getCopyright,
getDate,
getExplanation,
getHdurl,
getMediaType,
getServiceVersion,
getTitle,
getImageUrl,
} from "./index.js"; // imports all the functions;
```
```js
import * as APOD from "./index.js"; // imports all the functions;
```
### Example usage:
```JavaScript
const apiKey = process.env.NASA_API_KEY;
getCopyright(apiKey)
.then(copyright => console.log("Copyright:", copyright))
.catch(error => console.error(error));
getDate(apiKey)
.then(date => console.log("Date:", date))
.catch(error => console.error(error));
```
### 🤝 Contributing
Feel free to submit pull requests or issues on GitHub!
### License
MIT License
#### Additional Information
- The `BASE_URL` for the API is set using an environment variable (NASA_API_URL) for security reasons. If not provided, it defaults to the public API URL.
- The code is well-structured with modular functions for each property retrieval.
- Error handling ensures the code gracefully handles potential issues during API calls.
- It now includes improved security by explicitly checking for a missing API key and throwing an informative error message to guide users on setting it up.