![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
yr.no-interface
Advanced tools
HTTP wrapper for the yr.no/api.met.no API with support for streams
HTTP request wrapper for the yr.no/api.met.no weather service API with support for streams.
npm install yr.no-interface --save
All of these are in the /examples folder of this project.
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!
}
});
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));
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);
})
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
.
An instance is an object with functions attached. The functions are listed below.
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.
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.
FAQs
HTTP wrapper for the yr.no/api.met.no API with support for streams
The npm package yr.no-interface receives a total of 4 weekly downloads. As such, yr.no-interface popularity was classified as not popular.
We found that yr.no-interface demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.