# openweatherapi-js-sdk

> OpenWeatherMap.org Javascript SDK

Latest version **1.1.3** (published 2020-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install openweatherapi-js-sdk
pnpm add openweatherapi-js-sdk
yarn add openweatherapi-js-sdk
bun add openweatherapi-js-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2020-12-30 |
| First published | 2020-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 175.5 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Hamza MEHRI |
| Maintainers | bayoudhi |
| Keywords | openweatherapi, weather, api, node, sdk |

## Links

- npm: https://www.npmjs.com/package/openweatherapi-js-sdk
- Repository: https://github.com/bayoudhi/openweatherapi-js-sdk
- Issues: https://github.com/bayoudhi/openweatherapi-js-sdk/issues
- npm.io page: https://npm.io/package/openweatherapi-js-sdk

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2020-12-30
- 1.1.2 — 2020-12-29
- 1.1.1 — 2020-12-29
- 1.1.0 — 2020-12-29
- 1.0.10 — 2020-12-07
- 1.0.9 — 2020-12-07
- 1.0.8 — 2020-12-07
- 1.0.7 — 2020-12-07
- 1.0.6 — 2020-12-07
- 1.0.5 — 2020-12-07
- 1.0.4 — 2020-12-07
- 1.0.3 — 2020-12-06
- 1.0.2 — 2020-12-06
- 1.0.1 — 2020-12-06
- 1.0.0 — 2020-12-06

## 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:

```javascript
// 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.

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

const api = createAPI("your_api_key");
```

# Current Weather

## By city name

```javascript
// 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.

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

## By geographic coordinates

```javascript
// 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

```javascript
// 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

```javascript
// 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.

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

## By geographic coordinates

```javascript
// 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

```javascript
// 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](https://openweathermap.org/current#data)
- **lang** - You can use this parameter to get the output in your language. [Learn more](https://openweathermap.org/current#multi)

## 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 ❤️
 - Develop the new feature [One Call API](https://openweathermap.org/api/one-call-api)
 - Develop the  [5 day weather forecast API](https://openweathermap.org/forecast5)
 

 Thanks

---
_Source: https://npm.io/package/openweatherapi-js-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
