{"id":16162,"library":"openweather-api-node","title":"OpenWeather API Node.js Client","description":"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.","status":"active","version":"3.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/loloToster/openweather-api-node","tags":["javascript","weather","openweather","openweathermap","meteo","weather-api","air","pollution","api","typescript"],"install":[{"cmd":"npm install openweather-api-node","lang":"bash","label":"npm"},{"cmd":"yarn add openweather-api-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add openweather-api-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM projects (e.g., TypeScript or modern Node.js modules), the main class is a default export.","wrong":"import { OpenWeatherAPI } from 'openweather-api-node'","symbol":"OpenWeatherAPI","correct":"import OpenWeatherAPI from 'openweather-api-node'"},{"note":"For CommonJS projects, the main class is exported as a named property of the module object.","wrong":"const OpenWeatherAPI = require('openweather-api-node')","symbol":"OpenWeatherAPI","correct":"const { OpenWeatherAPI } = require('openweather-api-node')"},{"note":"Import only the type definition for configuration options, available since v1.3.0.","wrong":"import { OpenWeatherAPI_Options } from 'openweather-api-node'","symbol":"OpenWeatherAPI_Options","correct":"import type { OpenWeatherAPI_Options } from 'openweather-api-node'"}],"quickstart":{"code":"import OpenWeatherAPI from \"openweather-api-node\";\n\nconst weather = new OpenWeatherAPI({\n    key: process.env.OPENWEATHER_API_KEY ?? '', // Ensure your API key is set as an environment variable\n    locationName: \"New York\",\n    units: \"imperial\"\n});\n\nweather.getCurrent().then(data => {\n    console.log(`Current temperature in New York is: ${data.weather.temp.cur}\\u00B0F`);\n}).catch(error => {\n    console.error(\"Failed to fetch current weather:\", error.message);\n});\n\nweather.getForecast().then(data => {\n    console.log(`Forecast for New York (first entry): ${data.weather[0].temp.day}\\u00B0F`);\n}).catch(error => {\n    console.error(\"Failed to fetch forecast:\", error.message);\n});","lang":"typescript","description":"Demonstrates initializing the OpenWeatherAPI client with an API key and location, then fetching current weather and forecast data."},"warnings":[{"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.","message":"Starting 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.","severity":"breaking","affected_versions":">=3.1.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update all property access to use `camelCase` (e.g., `temp_cur` becomes `temp.cur`). Refactor any logic that used `mergeWeathers`.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"For ESM/TypeScript, use `import OpenWeatherAPI from 'openweather-api-node'`. For CommonJS, use `const { OpenWeatherAPI } = require('openweather-api-node')`.","message":"The 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`.","severity":"gotcha","affected_versions":">=2.0.0"},{"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.","message":"An API key from OpenWeatherMap is absolutely required for nearly all operations. Without a valid key, API requests will fail with authorization errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"For ESM/TypeScript, use `import OpenWeatherAPI from 'openweather-api-node'; new OpenWeatherAPI(...)`. For CommonJS, use `const { OpenWeatherAPI } = require('openweather-api-node'); new OpenWeatherAPI(...)`.","cause":"Attempting to instantiate the OpenWeatherAPI class incorrectly, often due to a mismatch between module import syntax (ESM vs. CommonJS) and the actual export.","error":"TypeError: OpenWeatherAPI is not a constructor"},{"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')`.","cause":"The OpenWeatherAPI instance was initialized without a valid API key.","error":"Error: No API key provided."},{"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`.","cause":"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.","error":"TS2305: Module '\"openweather-api-node\"' has no default export."},{"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.","cause":"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.","error":"Property 'weather' does not exist on type 'WeatherData' | 'OneCallData'."}],"ecosystem":"npm"}