Skip to content

utkuberkaykoc/space-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Space Image API 🚀

Fetches a space image from NASA based on a given day and month. Supports both Turkish and English month names. Returns the image in Base64 format.

NPM Version
Downloads
License


📌 Features

✅ Fetch NASA space images based on your birthday or a specific date 📆
Supports Turkish & English month names 🌍
✅ Returns Base64-encoded images 🖼️
No API key required 🔑
Works with Node.js & supports Promises


📦 Installation

Install via npm:

npm install space-image

Or using yarn:

yarn add space-image

🚀 Usage

Import the package

const { getSpaceImage } = require("space-image");

Fetch a space image by date

getSpaceImage(15, "january", "en")
  .then(data => console.log(data))
  .catch(err => console.error(err));

Example Response

{
  "date": "15 January",
  "base64Image": "/9j/4AAQSkZJRgABAQAAAQABAAD..."
}

📥 Saving the Image to a File

You can save the Base64-encoded image to a .jpg file using Node.js fs module:

const { getSpaceImage } = require("space-image");
const fs = require("fs");

async function downloadImage(day, month, lang = "en") {
  try {
    const data = await getSpaceImage(day, month, lang);
    fs.writeFileSync(`space_image_${day}_${month}.jpg`, Buffer.from(data.base64Image, "base64"));
    console.log(`✅ Image saved as space_image_${day}_${month}.jpg`);
  } catch (error) {
    console.error("❌ Failed to download image:", error.message);
  }
}

// Example usage
downloadImage(15, "january", "en");

📜 API Reference

getSpaceImage(day, month, lang)

Fetches a space image from NASA based on the given day and month.

  • Parameters:
    • day (number) → The day of the month (1-31).
    • month (string) → The name of the month in Turkish or English (e.g., "ocak" or "january").
    • lang (string, optional) → The response language ("tr" or "en"). Defaults to "en".
  • Returns: Promise<object> → JSON object with date and Base64-encoded image.

🛠️ Contributing

Contributions are welcome! Fork the repository, create a branch, make changes, and submit a PR. 🚀


📜 License

This project is licensed under the MIT License.


🌟 Support & Contact

🚀 Happy Coding! 🎮✨

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published