Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openweathermap-api-module

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openweathermap-api-module

Simple Node module to call the openweathermap API

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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 OpenWeatherMap
  • options Object? Options for configuration
    • options.request Function? Select with request option to use. Defaults to node-fetch
    • options.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 cityName
    • args.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

  • args

currentWeatherByCityId

Call Current weather for One location by city ID

Parameters

  • args Object Arguments for mixin handler
    • args.cityId Object Object with cityName
    • args.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 coordinates
    • args.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 code
    • args.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 Zoom
    • args.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 Zoom
    • args.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 Ids
    • args.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 city
  • 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

// api.openweathermap.org/data/2.5/weather?q=London
// api.openweathermap.org/data/2.5/weather?q=London,uk
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 City
  • 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

// api.openweathermap.org/data/2.5/weather?id=2643743
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

// api.openweathermap.org/data/2.5/weather?lat=35&lon=139
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

// api.openweathermap.org/data/2.5/weather?zip=94040,us
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

// api.openweathermap.org/data/2.5//box/city?bbox=12,32,15,37,10
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

// api.openweathermap.org/data/2.5//box/city?lat=55.5&lon37.5&cnt=10
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

// http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743
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

Keywords

FAQs

Package last updated on 02 Feb 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc