nws-wrapper
v1.0.0
Published
National Weather Service (US) API Wrapper for JS
Downloads
10
Maintainers
Readme
NWS Wrapper
This is a Node.js package that provides a simple API for accessing data from the National Weather Service (NWS) API.
Installation
To install this package, run the following command:
npm install nws-wrapper
Usage
getPointData(lat, lon)
This function retrieves the point data for a given latitude and longitude. It returns a Promise that resolves to an object containing the following properties:
id
: the URL of the API endpoint for this pointtype
: the type of the API endpoint for this pointgeometry
: an object containing the latitude and longitude of this pointproperties
: an object containing various properties of this point, including the forecast URL, the forecast grid URL, and the observation URL
Default response:
{
"id": "https://api.weather.gov/points/38.7845,-77.0888",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.0888,
38.7845
]
},
"properties": {
"cwa": "LWX",
"forecastOffice": "https://api.weather.gov/offices/LWX",
"gridX": 57,
"gridY": 74,
"forecast": "https://api.weather.gov/gridpoints/LWX/57,74/forecast",
"forecastHourly": "https://api.weather.gov/gridpoints/LWX/57,74/forecast/hourly",
"forecastGridData": "https://api.weather.gov/gridpoints/LWX/57,74",
"observationStations": "https://api.weather.gov/gridpoints/LWX/57,74/stations",
"relativeLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.091138,
38.790957
]
},
"properties": {
"city": "Merrifield",
"state": "VA",
"distance": {
"value": 3032.8744011284,
"unitCode": "unit:m"
},
"bearing": {
"value": 82,
"unitCode": "unit:degrees_true"
}
}
},
"forecastZone": "https://api.weather.gov/zones/forecast/VAZ052",
"county": "https://api.weather.gov/zones/county/VAC059",
"fireWeatherZone": "https://api.weather.gov/zones/fire/VAZ052",
"timeZone": "America/New_York",
"radarStation": "KLWX"
}
}
Example usage:
const { getPointData } = require('nws-wrapper');
getPointData(40.7128, -74.0060)
.then(pointData => {
console.log(pointData);
})
.catch(error => {
console.error(error);
});
getGrid(lat, lon)
This function retrieves the grid coordinates for a given latitude and longitude. It returns a Promise that resolves to a string containing the grid coordinates in the format "x,y".
Default response:
const { getGrid } = require('nws-wrapper');
getGrid(40.7128, -74.0060)
.then(grid => {
console.log(grid);
})
.catch(error => {
console.error(error);
});
checkWeatherWarnings(latitude, longitude)
This function checks for active weather warnings for a given latitude and longitude. It returns a Promise that resolves to an array of objects containing the following properties:
descr: the description of the weather warning hl: the headline of the weather warning If there are no active weather warnings, it returns a string indicating that there are no active weather warnings.
Default response:
"No active weather warnings found for this location."
Example usage:
const { checkWeatherWarnings } = require('nws-wrapper');
checkWeatherWarnings(40.7128, -74.0060)
.then(warnings => {
console.log(warnings);
})
.catch(error => {
console.error(error);
});
checkKeyword(headline)
This function checks if a given headline contains any of the keywords used for weather warnings. It returns a string containing the keywords found, separated by commas. If no keywords are found, it returns the string "NONE".
Default response:
"NONE"
Example usage:
const { checkKeyword } = require('nws-wrapper');
const headline = "Winter Storm Warning in effect";
const keywords = checkKeyword(headline);
console.log(keywords);
getRadarSingle(office)
This function retrieves the URL of a single-frame radar image for a given NWS office. It returns a string containing the URL.
Default response:
"undefined"
Example usage:
const { getRadarSingle, getRadarStation } = require('nws-wrapper');
const radarStation = await getRadarStation(40.7128, -74.0060);
const radarUrl = getRadarSingle(radarStation);
console.log(radarUrl);
getRadarLoop(office)
This function retrieves the URL of a animated radar image for a given NWS office. It returns a string containing the URL.
Default response:
"undefined"
Example usage:
const { getRadarLoop, getRadarStation } = require('nws-wrapper');
const radarStation = await getRadarStation(40.7128, -74.0060);
const radarUrl = getRadarLoop(radarStation);
console.log(radarUrl);
getNWSOffice(lat, lon)
This function retrieves the NWS Office for a given latitude and longitude. It returns a Promise that resolves to a string containing the NWS office in the format “NWS” (NWS being the office ID).
Default response:
"undefined"
Example usage:
const { getNWSOffice } = require('nws-wrapper');
const nwsOffice = await getNWSOffice(40.7128, -74.0060);
console.log(nwsOffice);
getRadarStation(lat, lon)
This function retrieves the radar station for a given latitude and longitude.. It returns a string containing the radar station ID.
Default response:
"undefined"
Example usage:
const { getRadarStation } = require('nws-wrapper');
const radarStation = await getRadarStation(40.7128, -74.0060);
console.log(radarStation);