Code Monkey home page Code Monkey logo

nws-api's Introduction

NWS API

NWS API is an API wrapper for the API provided by the National Weather Service.
The API provides forecasts, alerts, and other weather related data based on location (coordinates, or forecast grids).

More information on the National Weather Service API can be found here.

Installation

npm install nws-api-wrapper

Implementation

const NWS = require('nws-api-wrapper');

Functions & Examples

getStatus();

NWS.getStatus();

Description & Notes:

This function returns the status of the API using the base URL https://api.weather.gov


getLocationInfo();

NWS.getLocationInfo(<latitude>, <longitude>);

Description & Notes:

This function requires 2 parameters (latitude, and longitude), and will return an object of data about the coordinates such as grid coordinates, forecast links, and even the relative city, and state.


getForecast();

NWS.getForecast(<latitude>, <longitude>, <periods>);

Usage Example:

try {
    let response = await NWS.getForecast(39.7456, -97.0892, 3);
    // Handle response here.
}
catch (error) {
    // Handle error here.
}

Description & Notes:

This function has 3 parameters total, the first 2 (latitude, and longitude) are required, while the 3rd parameter (periods) is optional. The 3rd parameter if supplied must be a number between 1-14 otherwise an error will be thrown. If the period parameter is not supplied, the function will return all 14 periods.

This function will return an array of up to 14 forecast periods (each period will be an object). Each period is about a 12 hour timeframe (7AM-7PM & 7PM-7AM EST). If the function is called at 3PM EST, the first period won’t be a full 12 hours, instead that timeframe will be 3PM-7PM EST.


getHourlyForecast();

NWS.getHourlyForecast(<latitude>, <longitude>, <periods>);

Usage Example:

try {
    let response = await NWS.getHourlyForecast(39.7456, -97.0892, 24);
    // Handle response here.
}
catch (error) {
    // Handle error here.
}

Description & Notes:

This function has 3 parameters total, the first 2 (latitude, and longitude) are required, while the 3rd parameter (periods) is optional. The 3rd parameter if supplied must be a number between 1-156, otherwise an error will be thrown. If the period parameter is not supplied, the function will return all 156 periods.

Similar to the getForecast(); function, this will return an array of forecast periods (each period will be an object). Each period is 1 hour, with the exception of the first period if called after the beginning of an hour.


nws-api's People

Contributors

glitchical avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.