weathered 🌤⛈☀️🌨
A JavaScript wrapper for the National Weather Service API - built with TypeScript.
Source code
Documentation
A couple examples are below. There is also extensive typedoc generated documentation.
Installation
npm install weathered
Getting Started
Import and instantiate a client
import { Client } from 'weathered';
const client = new Client();
Get active weather alerts for a location (latitude and longitude)
const active = true;
const latitude = 35.6175667;
const longitude = -80.7709911;
const alerts = await client.getAlerts(active, { latitude, longitude });
alerts.features.forEach(feature => {
console.log(feature.properties.description);
console.log(feature.geometry);
});
Get all weather alerts (active or inactive) for a region
const alerts = await client.getAlerts(active, { region: 'AL' });
alerts.features.forEach(feature => {
console.log(feature.properties.description);
console.log(feature.geometry);
});
Get weather forecast for a location (latitude and longitude)
const forecast = await client.getForecast(latitude, longitude, 'baseline');
forecast.properties.periods.forEach(period => {
console.log(`${period.name}: ${period.detailedForecast}`);
});
Get the closest weather stations for a given latitude and longitude
const stations = await client.getStations(latitude, longitude);
stations.features.forEach(station => console.log(station.properties.name));
Get the closest weather station for a given latitude and longitude
const nearestStation = await client.getNearestStation(latitude, longitude);
if (nearestStation) {
console.log(nearestStation.properties.stationIdentifier);
}
Get weather observations for a given station
const nearestStation = await client.getNearestStation(latitude, longitude);
if (nearestStation) {
const { stationIdentifier } = nearestStation.properties;
const observations = await client.getStationObservations(stationIdentifier);
observations.features.forEach(obs => console.log(obs.properties.temperature));
}
Get the latest weather observation for a given station
const latestObservation = await client.getLatestStationObservations('KSFO');
console.log(latestObservation.properties.relativeHumidity);