Registry / http-networking / openweather-api-node

openweather-api-node

JSON →
library3.1.5jsnpmunverified

openweather-api-node is a lightweight JavaScript/TypeScript wrapper that simplifies interaction with various OpenWeather API endpoints, including Current Weather, Forecast, OneCall (version 3.0), Geocoding, Historical data, and Air Pollution data. Currently at version 3.1.5, it provides a stable and actively maintained interface for integrating weather data into Node.js applications. The package has undergone significant refactoring, including a full TypeScript rewrite in v2.0.0 and the removal of Axios in v3.1.0, making it more self-contained. While there isn't a strict release schedule, the library sees regular updates for new API features and improvements. Its primary differentiator is its comprehensive support for multiple OpenWeather APIs and full TypeScript typings out-of-the-box.

npm install openweather-api-node
INSTALL
IMPORT
SIG · OPENWEATHER-API-NO
O
openweather-api-node
http-networkingjavascriptv3.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenWeatherAPI
import OpenWeatherAPI from 'openweather-api-node'
import { OpenWeatherAPI } from 'openweather-api-node'
For ESM projects (e.g., TypeScript or modern Node.js modules), the main class is a default export.
OpenWeatherAPI
const { OpenWeatherAPI } = require('openweather-api-node')
const OpenWeatherAPI = require('openweather-api-node')
For CommonJS projects, the main class is exported as a named property of the module object.
OpenWeatherAPI_Options
import type { OpenWeatherAPI_Options } from 'openweather-api-node'
import { OpenWeatherAPI_Options } from 'openweather-api-node'
Import only the type definition for configuration options, available since v1.3.0.

Demonstrates initializing the OpenWeatherAPI client with an API key and location, then fetching current weather and forecast data.

import OpenWeatherAPI from "openweather-api-node"; const weather = new OpenWeatherAPI({ key: process.env.OPENWEATHER_API_KEY ?? '', // Ensure your API key is set as an environment variable locationName: "New York", units: "imperial" }); weather.getCurrent().then(data => { console.log(`Current temperature in New York is: ${data.weather.temp.cur}\u00B0F`); }).catch(error => { console.error("Failed to fetch current weather:", error.message); }); weather.getForecast().then(data => { console.log(`Forecast for New York (first entry): ${data.weather[0].temp.day}\u00B0F`); }).catch(error => { console.error("Failed to fetch forecast:", error.message); });
Debug
Known issues
breakingStarting with v3.1.0, the `axios` dependency was removed. If your application relied on `axios` being a transitive dependency or expected `axios`-specific error structures, you might need to adjust your error handling or explicitly install `axios` if still needed elsewhere.
fix
Review any code that might have indirectly relied on `axios` or its specific response/error formats. The library now uses native `fetch` or a lightweight alternative.
affects: >=3.1.0
breakingVersion 3.0.0 introduced support for the new OneCall API 3.0, and the return type of the `getHistory` method was changed. If you were using the older OneCall API, you might encounter breaking changes.
fix
For the old OneCall API, downgrade to `openweather-api-node@2.1.2`. Review the documentation for v3.x's `getHistory` method for updated return types and adapt your code accordingly.
affects: >=3.0.0
breakingVersion 2.0.0 was a complete rewrite in TypeScript. Variable styles in Weather Objects changed to `camelCase`, and the `mergeWeathers` method was removed. Existing code relying on older snake_case properties or the removed method will break.
fix
Update all property access to use `camelCase` (e.g., `temp_cur` becomes `temp.cur`). Refactor any logic that used `mergeWeathers`.
affects: >=2.0.0 <3.0.0
gotchaThe import style for the `OpenWeatherAPI` class differs between ESM (TypeScript/modern Node.js) and CommonJS environments. Incorrectly importing can lead to `TypeError: OpenWeatherAPI is not a constructor` or `TS2305: Module ... has no default export`.
fix
For ESM/TypeScript, use `import OpenWeatherAPI from 'openweather-api-node'`. For CommonJS, use `const { OpenWeatherAPI } = require('openweather-api-node')`.
affects: >=2.0.0
gotchaAn API key from OpenWeatherMap is absolutely required for nearly all operations. Without a valid key, API requests will fail with authorization errors.
fix
Ensure you have obtained an API key from OpenWeatherMap and pass it correctly during initialization via the `key` option or `setKey` method. Always protect your API keys.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: OpenWeatherAPI is not a constructor
Attempting to instantiate the OpenWeatherAPI class incorrectly, often due to a mismatch between module import syntax (ESM vs. CommonJS) and the actual export.
fix
For ESM/TypeScript, use `import OpenWeatherAPI from 'openweather-api-node'; new OpenWeatherAPI(...)`. For CommonJS, use `const { OpenWeatherAPI } = require('openweather-api-node'); new OpenWeatherAPI(...)`.
Error: No API key provided.
The OpenWeatherAPI instance was initialized without a valid API key.
fix
Ensure the `key` property is set in the constructor options, e.g., `new OpenWeatherAPI({ key: 'YOUR_API_KEY', ... })`, or by using `weather.setKey('YOUR_API_KEY')`.
TS2305: Module '"openweather-api-node"' has no default export.
A TypeScript project (likely configured for CommonJS module resolution or using an older compiler target) is attempting a default import where a named import is expected for CJS, or vice-versa with module interop settings.
fix
If targeting ESM, ensure `tsconfig.json` has `"module": "ESNext"` or similar. If targeting CommonJS, use `import * as OpenWeatherAPI from 'openweather-api-node'` and then `new OpenWeatherAPI.OpenWeatherAPI(...)` or adjust `allowSyntheticDefaultImports` in `tsconfig.json`.
Property 'weather' does not exist on type 'WeatherData' | 'OneCallData'.
This error can occur if the API response structure has changed, particularly after updating to v2.0.0 (camelCase changes) or v3.0.0 (getHistory return type), or if you are incorrectly accessing nested properties.
fix
Consult the current documentation for the exact response structure of the method you are calling. Ensure property names are `camelCase` and adjust nested accessors if the object shape has changed.
Upgrade
Version history
3.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
openweather-api-node — npm install openweather-api-node · libregistry