@shodlik_shomuratov/openweather-sdk
v2.0.5
Published
Software Development Kit(SDK) to get weather information related to given city easily.
Downloads
5
Maintainers
Readme
Open Weather SDK in Node.js
Introduction
Open Weather SDK is used to work with famous weather forecaster Open Weather features using Node.js, TypeScript. The package provides method(s) to get weather condition by city name.
This page presents the installation, basic usage and examples with different type of modes.
Used technologies:
Contents
Installation
- npm -
npm install @shodlik_shomuratov/openweather-sdk
- yarn -
yarn add @shodlik_shomuratov/openweather-sdk
- pnpm -
pnpm add @shodlik_shomuratov/openweather-sdk
Configuration
- Obtain your API_KEY from OpenWeather to use package properly!
- Instantiate SDK client and pass it to KameleoonProvider
import SDK from "@shodlik_shomuratov/openweather-sdk";
const sdk = new SDK("your_api_key");
async function outputWeather() {
const weatherData = await sdk.getCurrentWeather("Tashkent");
console.log(weatherData);
}
outputWeather();
Modes
- Default mode. In this mode you every time call the getCurrentWeather() method SDK makes a new request.
import SDK from "@shodlik_shomuratov/openweather-sdk";
cosnt sdk = new SDK("your_api_key", {
mode: "default"
});
async function outputWeather () {
const weatherData = await sdk.getCurrentWeather("Tashkent");
console.log(weatherData);
}
outputWeather();
- Polling mode. In polling mode in order to maintenance zero latency response, you get data from stored weather data and SDK makes a new request for you every 10 minutes.
import SDK from "@shodlik_shomuratov/openweather-sdk";
cosnt sdk = new SDK("your_api_key", {
mode: "polling"
});
async function outputWeather () {
const weatherData = await sdk.getCurrentWeather("Tashkent");
console.log(weatherData);
}
outputWeather();
Redis Store
If you want you can save updated weather data in your redis store. Only thing you have to do is give SDK redis options in the redis field.
import SDK from "@shodlik_shomuratov/openweather-sdk";
cosnt sdk = new SDK("your_api_key", {
mode: "polling",
redis: {
host: "127.0.0.1", // your redis host
port: 6379, // your redis port
username: "my_redis_username", // optional, if you have one
password: "my_redis_password", // optional, if you have one
}
});
async function outputWeather () {
const weatherData = await sdk.getCurrentWeather("Tashkent");
console.log(weatherData);
}
outputWeather();
Testing purposes
- You have to clone this repository into your local machine and install dependencies
npm install
- Change
.env.sample
into.env
and write your credentials in it.
OPEN_WEATHER_API_KEY=my_api_key
- Run test command
npm run test
Created by Shodlik Shomuratov