npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openweatherapi-js-sdk

v1.1.3

Published

OpenWeatherMap.org Javascript SDK

Downloads

34

Readme

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