Socket
Socket
Sign inDemoInstall

openweatherapi-js-sdk

Package Overview
Dependencies
2
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    openweatherapi-js-sdk

OpenWeatherMap.org Javascript SDK


Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

openweatherapi-js-sdk

Ready-to-use javascript library to consume OpenWeatherMap.org free services.

Request a free api key on http://openweathermap.org/appid.

Typescript supported ✅

Installation

Using npm:

// using npm
npm install openweatherapi-js-sdk --save

// using yarn
yarn add openweatherapi-js-sdk

How to Use

Instantiation

Import createAPI function from the installed library, and create your api using your existing api key, if you don't have a key, request a free one on http://openweathermap.org/appid.

const { createAPI } = require("openweatherapi-js-sdk");

const api = createAPI("your_api_key");

Current Weather

By city name

// Short example
api
  .weather
  .getWeatherByCityName({
    cityName: "London", // required
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

// Full example
api
  .weather
  .getWeatherByCityName({
    cityName: "London", // required
    stateCode: "uk", // optional
    countryCode: "GB", // optional
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By city id

List of city ID 'city.list.json.gz' can be downloaded from this link http://bulk.openweathermap.org/sample.

// Example
api
  .weather
  .getWeatherByCityId({
    cityId: 2172797, // required
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By geographic coordinates

// Example
api
  .weather
  .getWeatherByGeo({
    latitude: 37, // required
    longitude: 10, // required
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By ZIP code

// Example
api
  .weather
  .getWeatherByZipCode({
    zipCode: 94040, // required
    countryCode: "us", // optional
    lang: "fr", // optional
    units: "metric", // optional - standard, metric and imperial units are available.
  })
  .then((weather) => console.log("Weather object is", weather));

5 day weather forecast

By city name

// Short example
api
  .forecast
  .getForecastByCityName({
    cityName: "London", // required
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

// Full example
api
  .forecast
  .getForecastByCityName({
    cityName: "London", // required
    stateCode: "uk", // optional
    countryCode: "GB", // optional
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By city id

List of city ID 'city.list.json.gz' can be downloaded from this link http://bulk.openweathermap.org/sample.

// Example
api
  .forecast
  .getForecastByCityId({
    cityId: 2172797, // required
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By geographic coordinates

// Example
api
  .forecast
  .getForecastByGeo({
    latitude: 37, // required
    longitude: 10, // required
    lang: "fr", // optional
    units: "metric", // optional
  })
  .then((weather) => console.log("Weather object is", weather));

By ZIP code

// Example
api
  .forecast
  .getForecastByZipCode({
    zipCode: 94040, // required
    countryCode: "us", // optional
    lang: "fr", // optional
    units: "metric", // optional - standard, metric and imperial units are available.
  })
  .then((weather) => console.log("Weather object is", weather));

Common Options

  • units - Units of measurement. standard, metric and imperial units are available. If you do not use the units parameter, standard units will be applied by default. Learn more
  • lang - You can use this parameter to get the output in your language. Learn more

Test

This package is tested using jest. You can find the tests in the /tests folder. This package is developed using the TDD approach.

Feel free 😊 to enhance it and to add more tests 🧪🧪🧪

TODO

Feel free to contribute to this library ❤️

Thanks

Keywords

FAQs

Last updated on 30 Dec 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc