Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
openweather-api-node
Advanced tools
Simple Node.js package that makes it easy to work with OpenWeather API
Simple package that makes it easy to work with OpenWeather API.
This package is a wrapper for OpenWeather API. If you want to learn how to use this package check out examples in examples folder. The only thing that you need to get started is API key if you don't have one go to OpenWeatherMap website and get it. For now this package supports only a part of the API but we are planning on adding more features like: triggers, maps and all the other stuff that is available for free in OpenWeatherMap API.
Currently Supported APIs:
npm i openweather-api-node
const OpenWeatherAPI = require("openweather-api-node")
let weather = new OpenWeatherAPI({
key: "put-key-here",
locationName: "New York",
units: "imperial"
})
/*
you can use setters as well:
weather.setKey("put-key-here")
weather.setLocationByName("New York")
...
*/
weather.getCurrent().then(data => {
console.log(`Current temperature in New York is: ${data.weather.temp.cur}\u00B0F`)
})
Description:
Getter for global options.
Returns:
Global options - Object
Example:
let options = weather.getGlobalOptions()
See also: options
Description:
Sets global API key.
Arguments:
Example:
weather.setKey("key")
Description:
Getter for global key.
Returns:
Global API key - String
Example:
let key = weather.getKey()
Description:
Sets global language (Language must be listed here).
Arguments:
Example:
weather.setLanguage("en")
See also: options, getLanguage
Description:
Getter for global language.
Returns:
Global language - String
Example:
let language = weather.getLanguage()
See also: options, setLanguage
Description:
Sets global units.
Arguments:
Example:
weather.setUnits("imperial")
Description:
Getter for global units.
Returns:
Global units - String
Example:
let units = weather.getUnits()
Description:
Sets global location by provided name. The name
argument will basically replace the q
parameter in call described here.
Arguments:
Example:
weather.setLocationByName("London")
See also: options, getLocation
Description:
Sets global location by provided coordinates.
Arguments:
Example:
weather.setLocationByCoordinates(40.71, -74)
See also: options, getLocation
Description:
Sets global location by provided zip/post code. The zipCode
argument will basically replace the zip
parameter in call described here.
Arguments:
{zip code},{country code}
Example:
weather.setLocationByZipCode("E14,GB")
See also: options, getLocation
async
getLocation(options = {})Description:
Getter for location.
Arguments:
Returns:
location - Object
Example:
let location = await weather.getLocation()
// or with options
location = await weather.getLocation({locationName: "Tokio"})
See also: options, setLocationByName, setLocationByCoordinates
async
getCurrent(options = {})Description:
Getter for current weather.
Arguments:
Returns:
Weather object of current weather - Object
Example:
let current = await weather.getCurrent()
// or with options
current = await weather.getCurrent({units: "metric"})
See also: options, Weather Object
async
getMinutelyForecast(limit = Number.POSITIVE_INFINITY, options = {})Description:
Getter for minutely weather.
Arguments:
Returns:
Array of Weather objects, one for every next minute (Empty if API returned no info about minutely weather) - Array
Example:
let minutely = await weather.getMinutelyForecast()
// or with limit
minutely = await weather.getMinutelyForecast(10)
// here minutely.length won't be larger than 10
See also: options, Weather Object
async
getHourlyForecast(limit = Number.POSITIVE_INFINITY, options = {})Description:
Getter for hourly weather.
Arguments:
Returns:
Array of Weather objects, one for every next hour (Empty if API returned no info about hourly weather) - Array
Example:
let hourly = await weather.getMinutelyForecast()
// or with limit
hourly = await weather.getMinutelyForecast(5)
// here hourly.length won't be larger than 5
See also: options, Weather Object
async
getDailyForecast(limit = Number.POSITIVE_INFINITY, includeToday = false, options = {})Description:
Getter for daily weather.
Arguments:
Returns:
Array of Weather objects, one for every next day (Empty if API returned no info about daily weather) - Array
Example:
let daily = await weather.getDailyForecast()
// or with limit
daily = await weather.getDailyForecast(3)
// here daily.length won't be larger than 3
See also: options, Weather Object
async
getToday(options = {})Description:
Getter for today's weather. Equivalent to:
let today = (await weather.getDailyForecast(1, true, options))[0]
Not the same as current weather. getCurrent()
returns current weather and this method returns summary of the whole present day.
Arguments:
Returns:
Weather object of today's weather - Object
Example:
let today = await weather.getToday()
// or with options
today = await weather.getToday({coordinates:{
lat: -33.84,
lon: 151.18
}})
See also: options, Weather Object, getDailyForecast
async
getAlerts(options = {})Description:
Getter for alerts.
Arguments:
Returns:
Alerts (undefined
if API returned no info about alerts) - Object
Example:
let alerts = await weather.getAlerts()
See also: options
async
getEverything(options = {})Description:
Getter for every type of weather call and alerts.
Arguments:
Returns:
Object that looks like this:
{
lat: latitude of the location,
lon: longitude of the location,
timezone: timezone of the location,
timezone_offset: timezone offset of the location,
current: current weather object,
minutely: array of minutely weather objects,
hourly: array of hourly weather objects,
daily: array of daily weather objects,
alerts: alerts
}
Example:
let everything = await weather.getEverything()
let current = everything.current
let minutely = everything.minutely
// and so on...
See also: options, Weather Object
async
getHistory(dt, options = {})Description:
Getter for historical data about weather.
Arguments:
Returns:
Object that looks like this:
{
lat: latitude of the location,
lon: longitude of the location,
timezone: timezone of the location,
timezone_offset: timezone offset of the location,
current: weather object of current data of the time given,
hourly: data block containing hourly historical data starting at 00:00 on the requested day and continues until 23:59 on the same day (UTC time)
}
Example:
let history = await weather.getHistory(new Date().getTime() - 7200)
See also: options, Weather Object
Description:
Merges weather objects. Useful if for example you want to get minutely weather object but with more data than only rain volume, in this case you can merge minutely weather object with current weather object and get full weather object with data in nth minutes.
Arguments:
Returns:
Merged object of weather provided in weathers parameter - Object
Example:
let current = await weather.getCurrent()
let minutely = await weather.getMinutelyForecast()
let full = weather.mergeWeathers([minutely[20], current])
See also: Weather Object
async
getCurrentAirPollution(options = {})Description:
Getter for current data about air pollution.
Arguments:
Returns:
Air Pollution Object with data about current pollution - Object
Example:
let currentAirPollution = await weather.getCurrentAirPollution()
See also: options, Air Pollution Object
async
getForecastedAirPollution(limit = Number.POSITIVE_INFINITY, options = {})Description:
Getter for future data about air pollution. (Only five days ahead)
Arguments:
Returns:
Array of Air Pollution Objects with data about future pollution - Array
Example:
let futureAirPollution = await weather.getForecastedAirPollution(12) // limit to 12 hours
See also: options, Air Pollution Object
async
getHistoryAirPollution(from, to, options = {})Description:
Getter for historical data about air pollution
WARNING⚠️- Historical data is accessible from 27th November 2020
Arguments:
Returns:
Array of Air Pollution Objects with data about historical pollution - Array
Example:
let historyAirPollution = await weather.getHistoryAirPollution(new Date(2021, 9, 27), new Date(2021, 10, 11)) // get data from 27 October 2021 to 11 November 2021
See also: options, Air Pollution Object
This package use so called options, options define: API key, coordinates, units etc. Structure of options:
{
key: "your API key" - String,
language: "language to use" - String,
units: "units to use" - String,
locationName: "name of the location" - String,
zipCode: "'zip code' of the location" - String,
coordinates: {
lat: "latitude of the location" - Number,
lon: "longitude of the location" - Number
}
}
In the constructor of the class you can pass object that will define global options, they will be used by default in any method that uses options (ex. weather calls).
Some methods have options
argument which can be used to specify options only for this call. Options specified in options
argument will override global options. for example if your global options look like this:
{
key: "xyz",
locationName: "Moscow"
} // global options
and you pass options that look like this:
{
locationName: "Chicago"
} // options passed to `options` argument
actual used options will look like this:
{
key: "xyz",
locationName: "Chicago"
} // actual used options
because every option specified in options
argument will override the corresponding global option.
When using raw API the problem might be getting your head around how unorganised the responses might be. This package simplifies this and makes every returned object the same structure. Every weather object will look like this:
// property: "Description" - type
{
lat: "Geographical coordinates of the location (latitude) " - Number,
lon: "Geographical coordinates of the location (longitude)" - Number,
dt: "Current time, Unix, UTC or Time of the forecasted data, Unix, UTC" - Date,
timezone: "Timezone name for the requested location" - String,
timezone_offset: "Shift in seconds from UTC" - Number,
astronomical: {
sunrise: "Sunrise time, Unix, UTC" - Date,
sunset: "Sunset time, Unix, UTC" - Date,
moonrise: "The time of when the moon rises for this day, Unix, UTC" - Date,
moonset: "The time of when the moon sets for this day, Unix, UTC" - Date,
moon_phase: "Moon phase. 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon' and 0.75 is 'last quarter moon'. The periods in between are called 'waxing crescent', 'waxing gibous', 'waning gibous', and 'waning crescent', respectively." - Number
},
weather: {
temp: { // Actual temperature. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
cur: "Current temperature or estimated temperature (in hourly forecast)" - Number,
morn: "Morning temperature." - Number,
day: "Day temperature." - Number,
eve: "Evening temperature." - Number,
night: "Night temperature." - Number,
min: "Lowest daily temperature." - Number,
max: "Highest daily temperature." - Number
},
feels_like: { // This accounts for the human perception of weather. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
cur: "Current temperature or estimated temperature (in hourly forecast)." - Number,
morn: "Morning temperature." - Number,
day: "Day temperature." - Number,
eve: "Evening temperature." - Number,
night: "Night temperature." - Number
},
pressure: "Atmospheric pressure on the sea level, hPa" - Number,
humidity: "Humidity, %" - Number,
dew_point: "Atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit." - Number,
clouds: "Cloudiness, %" - Number,
uvi: "The maximum value of UV index for the day" - Number,
visibility: "Average visibility, metres" - Number,
wind: { // Wind statistics. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
speed: "Wind speed." - Number,
gust: "Wind gust." - Number,
deg: "Wind direction, degrees (meteorological)" - Number
},
pop: "Probability of precipitation" - Number,
rain: "Precipitation volume, mm" - Number,
snow: "Snow volume, mm" - Number,
condition_id: "Weather condition id (https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2)" - Number,
main: "Group of weather parameters (Rain, Snow, Extreme etc.)" - String,
description: "Description of the weather" - String,
icon: {
url: "Weather icon url." - String,
raw: "Weather icon id." - String
}
}
}
⚠️ API does not specify every value in every call so some of those values might be undefined
for example daily weather object won't have weather.temp.cur!
// property: "Description" - type
{
lat: "Geographical coordinates of the location (latitude)" - Number,
lon: "Geographical coordinates of the location (longitude)" - Number,
dt: "Date and time, UTC" - Date,
dt_raw: "Date and time, Unix, UTC" - Number,
aqi: "Air Quality Index" - Number,
aqi_name: "String substitute of aqi field (only english)" - String,
components: {
co: "Сoncentration of CO (Carbon monoxide), μg/m3" - Number,
no: "Сoncentration of NO (Nitrogen monoxide), μg/m3" - Number,
no2: "Сoncentration of NO2 (Nitrogen dioxide), μg/m3" - Number,
o3: "Сoncentration of O3 (Ozone), μg/m3" - Number,
so2: "Сoncentration of SO2 (Sulphur dioxide), μg/m3" - Number,
pm2_5: "Сoncentration of PM2.5 (Fine particles matter), μg/m3" - Number,
pm10: "Сoncentration of PM10 (Coarse particulate matter), μg/m3" - Number,
nh3: "Сoncentration of NH3 (Ammonia), μg/m3" - Number
}
}
FAQs
Simple package that makes it easy to work with OpenWeather API
The npm package openweather-api-node receives a total of 217 weekly downloads. As such, openweather-api-node popularity was classified as not popular.
We found that openweather-api-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.