weather-forecaster
weather-forecaster is a NPM module that will allow you to easily access the current and detailed weather conditions of any city in any country that you prefer!
Installation
npm install weather-forecaster
Properties
Field | Type | Unit | Description |
---|
date | object | | The date that the observation pertains (both numeric and long date formats) |
location | string | | Name of the location (City, Country) |
location_woeid | integer | | Where On Earth ID |
humidity_percentage | integer | percentage | |
weather_state | string | | Name of the weather state |
weather_state_iconURL | string | | Icon of the weather state (SVG format) |
air_pressure_hPa | float | hPa | |
wind_speed | object | kmh, mph | |
wind_direction | string | compass point | Compass point of the wind direction |
temp_celcius | object | centigrade | |
temp_fahrenheit | object | fahrenheit | |
visibility_range | object | km, miles | Measure of the distance which the weather state can be clearly discerned |
Usage
Since this package's structure is asynchronous you have to use "async-await" or ".then()" structures when using the module.
Example usages with these structures are given below.
- Getting all the data with IIFE:
const weather_forecast = require("weather-forecaster");
(async () => {
const data = await weather_forecast("san francisco");
console.log(data);
})();
- Getting all the data with .then():
const weather_forecast = require("weather-forecaster");
weather_forecast("istanbul").then(data => {
console.log(data);
});
- Getting all the data with async-await:
const weather_forecast = require("weather-forecaster");
async function myWeatherData(query) {
const data = await weather_forecast(query);
console.log(data);
};
myWeatherData("new york");
- Destructuring & getting specific data:
const weather_forecast = require("weather-forecaster");
async function myWeatherData(query) {
const data = await weather_forecast(query);
const { weather_state, temp_celcius } = data;
console.log(weather_state);
console.log(data.weather_state);
const { lowest, highest, current } = temp_celcius;
const first_array = [
lowest,
highest,
current
];
const second_array = [
temp_celcius.lowest,
temp_celcius.highest,
temp_celcius.current
];
const third_array = [
data.temp_celcius.lowest,
data.temp_celcius.highest,
data.temp_celcius.current
];
console.log(first_array);
console.log(second_array);
console.log(third_array);
};
myWeatherData("new york");
License
Licensed under The MIT License (MIT).
For the full copyright and license information,
please view the LICENSE file.