api-reader-package
v1.0.5
Published
This package helps you to read APIs easily.
Downloads
10
Readme
API Reader Package
Overview:
The api-reader-package
is a lightweight Node.js package designed to help developers easily fetch data from APIs. It uses axios
for making HTTP requests and dotenv
for managing environment variables, allowing for secure handling of API keys and URLs.
Features:
- Simple API Requests: Easily fetch data from APIs with minimal setup.
- Environment Variable Management: Securely manage API keys and URLs using
.env
files. - Lightweight: Minimal dependencies ensure fast installation and performance.
Installation: To install the package, use NPM:
npm install api-reader-package
Usage:
- Install the package (if you haven't already) using:
npm install api-reader-package
- Create a
.env
file in the root of your project to store your API URL and API key. Example content for.env
:
API_URL=https://newsapi.org/v2/top-headlines
API_KEY=your_api_key_here
- Import and use the package in your project with the following code:
import aniData from 'api-reader-package';
(async () => {
const apiUrl = process.env.API_URL;
const apiKey = process.env.API_KEY;
try {
const data = await aniData(apiUrl, apiKey);
console.log(JSON.stringify(data, null, 2));
} catch (error) {
console.error('Error fetching data:', error.message);
}
})();
Example:
This package allows you to quickly set up and fetch data from an API by simply providing the API URL and an API key in a .env
file. The data is returned in JSON format and can be easily manipulated or displayed as needed.