A package to retrieve weather information for a specified location.
/** If ESM */
import getWeather from "weather";
or
import { getWeather } from "weather";
/** If CJS */
const { getWeather } = require("weather");
const location = "Singapore"; // can be any location name or zip code
const weatherData = await getWeather(location);
.catch((error) => {
console.log(error);
return undefined;
});
if (!weatherData) return;
. . . // do something with the weather data
// output from the above code
{
humidity: '90',
feelslike: '29',
temperature: '26',
location: 'Singapore',
wind: '5 km/h Southeast',
weather: 'Mostly cloudy',
image: 'http://blob.weather.microsoft.com/static/weather4/en-us/law/27.gif'
}
• WeatherData for the location is not found.
• MSN weather service does not return any valid results.
• Location is not specified or location name is too long ( > 50 ).