OpenWeather API Node.js Client

3.1.5 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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);
});

view raw JSON →