npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yr.no-interface

v1.2.0

Published

HTTP wrapper for the yr.no/api.met.no API with support for streams

Downloads

42

Readme

yr.no-interface

TravisCI npm version Coverage Status

HTTP request wrapper for the yr.no/api.met.no weather service API with support for streams.

Install

npm install yr.no-interface --save

Examples

All of these are in the /examples folder of this project.

Callback Example

const yrno = require('yr.no-interface')({
  request: {
    timeout: 25000
  }
});

yrno.locationforecast({
  query: {
    // Get weather for Dublin, Ireland
    lat: 53.3478,
    lon: 6.2597
  },

  // The locationforecast API version to call
  version: 1.9
}, function (err, xml) {
  if (err) {
    // Something went wrong...
  } else {
    // We got an XML response!
  }
});

Streaming Example

Streams are one of the most powerful features in node.js. They allow you to perform I/O while using a tiny amount of memory since they pass data through the process in small "chunks".

Using streams is useful for certain response types such as the radar API since it returns a large GIF file that could use a large amount of the node.js process memory if loaded into a callback

Below we use a stream to pipe the HTTP respone from the yr.no API to a file on our machine.

const fs = require('fs');
const path = require('path');
const yrno = require('yr.no-interface')({
  request: {
    timeout: 25000
  }
});

// response data will be written to a file called res.xml in the
// directory this script is being run from
const filepath = path.join(process.cwd(), 'weather.xml');

yrno.locationforecast({
  query: {
    lat: 53.3478,
    lon: 6.2597
  },
  version: 1.9
})
  .pipe(fs.createWriteStream(filepath));

Promises Example

This module does not support promises by default. Here's how you could get Promise support:

const Promise = require('bluebird');

// Now all functions will return promises. Can also use a module like "pify"
const yrno = Promise.promisifyAll(
  require('yr.no-interface')({
    request: {
      timeout: 25000
    }
  })
);

// Note the "Async" added to use teh promise version
yrno.locationforecastAsync({
  query: {
    lat: 53.3478,
    lon: 6.2597
  },
  version: 1.9
})
   .then((xml) => {
    console.log('weather xml is - ', xml);
  })

API

module

This module exports a single function that must be called to get an API wrapper.

// Get an API wrapper instance with a default request timeout of 25 seconds
const yrno = require('yr.no-interface')({
  request: {
    // Can pass anything supported by the request module here.
    // Passing "qs" or "url" will fail since the module will overwrite them
    timeout: 25000
  }
});

Returns an API instance.

instance

An instance is an object with functions attached. The functions are listed below.

instance.FUNCTION

All functions on an instance contain the same signature of yrno.func([params[, callback]), e.g yrno.locationforecast(params, callback).

callback is optional. If no callback is provided a stream is returned so you can use node's stream awesomeness to pass data around. params should contain the querystring params as specified at the yr.no docs.

Each request must specify params.version as the met.no API requires this.

instance functions

  • errornotifications
  • extremeforecast
  • extremesWWC
  • forestfireindex
  • geosatellite
  • gribfiles
  • icemap
  • lightning
  • locationforecast
  • locationforecastLTS
  • metalerts
  • metgm
  • mountaineasterobservations
  • nowcast
  • oceanforecast
  • polarsatellite
  • probabilityforecast
  • radar
  • radarlightning
  • sigmets
  • spotwind
  • subjectiveforecast
  • sunrise
  • tafmetar
  • temperatureverification
  • textforecast
  • textlocation
  • tidalwater
  • turbulence
  • uvforecast
  • upperwindweather
  • verticalprofile
  • weathericon

Contributors

  • @ktrance
  • @clux
  • @Oisann

CHANGELOG

  • 1.2.0 - Updated to use https://api.met.no instead of the deprecated http://api.yr.no - thanks @antonmarsden

  • 1.1.0 - Updated API endpoints to match api.met.no - thanks @ktrance.

  • 1.0.1 - Patch for security vulnerability in request through qs module.

  • 1.0.0 - Initial stable release.