openweathermap-api-module
Simple Node module to call the openweathermap API
This wrapper is based on the free tier of OpenWeatherMap API.
You can get your API key here.
Table of Contents
Install
$ npm install openweathermap-api-module
Usage
const OpenWeatherMapRequests = require('openweathermap-api-module')
const apiKey = 'api key'
const client = new OpenWeatherMapRequests(apiKey)
client.currentWeatherByCityName('boston').then(console.log).catch(console.error)
Check out the Openweathermap API documentation for more information!
API
Table of Contents
constructor
Mixin for handling API requests options
Parameters
apiKey
String API key from OpenWeatherMapoptions
Object? Options for configuration
options.request
Function? Select with request option to use. Defaults to node-fetchoptions.config
Object? Configuration for fetch request
Examples
const client = new OpenWeatherMapRequest(ApiKey, {})
currentWeatherByCityName
Call Current weather for One location by city Name
Parameters
args
Object Arguments for mixin handler
args.cityName
Object Object with cityNameargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCityName({cityName: 'boston,us'})
client.currentWeatherByCityName({cityName: 'boston,us', lang: 'fr'})
Returns Object response - Object with data from request Type
currentWeatherByCityName
Mixin for handling API requests options
Parameters
currentWeatherByCityId
Call Current weather for One location by city ID
Parameters
args
Object Arguments for mixin handler
args.cityId
Object Object with cityNameargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCityId({cityId: 2643743})
client.currentWeatherByCityId({cityId: '2643743', units: 'metric'})
Returns Object response - Object with data from request Type
currentWeatherByGeoCoordinates
Call Current weather for One location by Geographic Coordinates
Parameters
args
Object Arguments for mixin handler
args.coordinates
Object Object with geographic coordinatesargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByGeoCoordinates({coordinates: { lon:'139.01', lat:'35.02' } })
client.currentWeatherByGeoCoordinates({coordinates: { lon:'139.01', lat:'35.02' }, lang: 'fr' })
Returns Object response - Object with data from request Type
currentWeatherByZipCode
Call Current weather for One location by Zipcode
Parameters
args
Object Arguments for mixin handler
args.zipCode
Object Object with City Zip codeargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByZipCode({ zipCode: '90247,us' })
client.currentWeatherByZipCode({ zipCode: '90247,us', lang: 'fr' })
Returns Object response - Object with data from request Type
currentWeatherByRectangleZone
Call Current weather for many locations by Rectangle Box
Parameters
args
Object Arguments for mixin handler
args.bbox
Object Object with Bounding box coordinates and Zoomargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByRectangleZone({ bbox: { lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' } })
client.currentWeatherByRectangleZone({ bbox: { lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' }, units: 'imperial' })
Returns Object response - Object with data from request Type
currentWeatherByCircleZone
Call Current weather for many locations by Circle Radius
Parameters
args
Object Arguments for mixin handler
args.bbox
Object Object with Bounding box coordinates and Zoomargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCircleZone({ circle: { lat: 55.5, lon: 37, cnt: 10 } })
client.currentWeatherByCircleZone({ circle: { lat: 55.5, lon: 37, cnt: 10 }, format: 'html' })
Returns Object response - Object with data from request Type
currentWeatherByCityIds
Call Current weather for many locations by City Ids
Parameters
args
Object Arguments for mixin handler
args.cityIds
Object Object with City Idsargs.format
Object? Format of return request (json|xml|html)args.units
Object? Format of unit used to return data (metric|imperial)args.lang
Object? Language of returned data
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherBy({ cityIds: [524901,703448,2643743] })
client.currentWeatherBy({ cityIds: [524901,703448,2643743], lang: 'fr' })
Returns Object response - Object with data from request Type
constructor
Current Weather API handler. Key is inherited from OpenWeatherMapRequests
Parameters
apiKey
baseUrl
baseUrl-null
String API base URL from OpenWeatherMap API
Examples
const client = new WeatherApiHandler('Api_key','base_url')
getOneLocationByCityName
Call Current weather for One location by city Name
Parameters
cityName
String Name of cityargs
(optional, default {}
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByCityName('boston')
client.getLocationByCityName('London,uk')
client.getLocationByCityName('tokyo', { units: 'imperial' })
client.getLocationByCityName('tokyo', { format: 'xml', units: 'imperial', lang='fr' })
Returns Object requestResponse - Return Object from API call
getOneLocationByCityId
Call Current weather for One location by ID
Parameters
cityId
(String | Number) Id of the Cityargs
(optional, default {}
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByCityId(2643743)
client.getLocationByCityId('2643743')
Returns Object requestResponse - Return Object from API call
getOneLocationByGeoCoordinates
Call Current weather for One location by Coordinates
Parameters
coordinates
Object Object including Coordinates. Ex: { lat: 139.01, lon: 35.02 }
args
(optional, default {}
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByGeoCoordinates({lon: 139.01, lat: 35.02})
client.getLocationByGeoCoordinates({lon: 139.01, lat: 35.02}, { format: 'xml' })
Returns Object requestResponse - Return Object from API call
getOneLocationByZipCode
Call Current weather for One location by Zip Codes
Parameters
zipCode
args
(optional, default {}
)zipcode
String Zipcode from Country, ex: 'zipcode,country' (optional, default "90247,us"
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByZipCode('94040,us')
Returns Object requestResponse - Return Object from API call
getManyLocationsByRectangleZone
Call current weather data for several cities using a Bounding Box
bbox bounding box [lon-left,lat-bottom,lon-right,lat-top,zoom]
Parameters
bbox
Object Bounding Box for location. Example: bbox={ lonLeft: '0', latBottom: '0', lonRight: '0', latTop: '0', zoom: '0' }args
(optional, default {}
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByRectangleZone({ lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' })
client.getManyLocationsByRectangleZone({ lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' }, { units: 'metric' })
Returns Object requestResponse - Return Object from API call
getManyLocationsByCircleZone
Call current weather data for several cities using a Longitude and Latitude and get all cities around it
Parameters
circle
Object Circle object with longitude, latitude and number of cities to show ex: { lat: 55.5, lon: 37, cnt: 10 }args
(optional, default {}
)options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByCircleZone({ lat: 55.5, lon: 37, cnt: 10 })
client.getManyLocationsByCircleZone({ lat: 55.5, lon: 37, cnt: 10 }, { lang: 'fr' })
Returns Object requestResponse - Return Object from API call
getManyLocationsByCityIds
Call for several city IDs
Parameters
cityIds
args
(optional, default {}
)citiIds
Array Array filled with city IDs, ex: [524901,703448,2643743]options
Object? options for request
options.format
String Format of request that is returned(json|xml|html) (optional, default json
)options.units
String Format of unit used for returned data (metric|imperial) (optional, default standard
)options.lang
String Language of returned data (optional, default eng
)
Examples
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByRectangleZone([524901,703448,2643743])
client.getManyLocationsByRectangleZone([524901,703448,2643743], { lang: 'fr' })
Returns Object requestResponse - Return Object from API call