Need help with weather?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

noazark
201 Stars 110 Forks MIT License 119 Commits 6 Opened issues

Description

real weather for Javascript

Services available

!
?

Need anything else?

Contributors list

# 199,243
chef-co...
chef-re...
Shell
python3
21 commits
# 387,589
JavaScr...
19 commits
# 545,364
JavaScr...
4 commits
# 118,561
HTML
JavaScr...
Shell
vimeo
1 commit

Weather.js

Build Status npm GitHub license

About

Weather.js was designed to be a conclusive JavaScript weather library built around the OpenWeatherMap API (no affiliation). Since other providers format their output differently, currently OpenWeatherMap is the only source provider.

Weather.js is still in early development so expect changes and please contribute! Among the features I hope to incorporate:

  • historical weather information
  • API key usage (but there is a beta version!)
  • more data sources
  • more conversions!

Note: As stated above there are plans to add more providers in the future. If you have suggestions for other providers that you'd like to see please create a new issue with info about the provider and a link to the provider's API.

Weather.js was originally created by Noah Smith and is currently maintained by PallasStreams.

Install

Weather.js works in the browser and Node.js. Take your pick, For use in the browser, download the most recent version on GitHub. For use in Node, just install using your NPM package manager of choice. Currently Node has an old version of the library available but it will be updated soon.

npm install -g weather.js

Testing

To run the JavaScript unit tests run:

bash
npm run test

Usage

At the moment you can access the current weather conditions and the forcast for any city. By default it will use the closes match as returned by OpenWeatherMap.

// API Key methods
var apiKey = '12345';
Weather.setApiKey( apiKey );
var tempApiKey = Weather.getApiKey();

// Language methods var langugage = "de"; // set the language to German - libraries default language is "en" (English) Weather.setLanguage( langugage ); var tempLanguage = Weather.getLanguage();

var cityId = '4393217';

// Get current weather for a given city Weather.getCurrent( 'Kansas City', function( current ) { console.log( [ 'Currently:', current.temperature(), 'and', current.conditions() ].join( ' ' ); ); } );

// Get current weather for a given city using the city id Weather.getCurrentByCityId( cityId, function( current ) { console.log( [ 'Currently:', current.temperature(), 'and', current.conditions() ].join( ' ' ); ); } );

// Get the current weather for a given city using the latitude and longitude var lat = 39.100, long = -94.579; Weather.getCurrentByLatLong( lat, long, function( current ) { console.log( [ 'Currently:', current.temperature(), 'and', current.conditions() ].join( ' ' ); ); } );

// Get the forecast for a given city Weather.getForecast( 'Kansas City', function( forecast ) { console.log( 'Forecast High in Kelvin: ' + forecast.high() ); console.log( 'Forecast High in Fahrenheit' + Weather.kelvinToFahrenheit( forecast.high() ) ); console.log( 'Forecast High in Celsius' + Weather.kelvinToCelsius( forecast.high() ) ); } );

// Get the forecast for a given city using the city id Weather.getForecastByCityId( cityId, function( forecast ) { console.log( 'Forecast High in Kelvin: ' + forecast.high() ); console.log( 'Forecast High in Fahrenheit' + Weather.kelvinToFahrenheit( forecast.high() ) ); console.log( 'Forecast High in Celsius' + Weather.kelvinToCelsius( forecast.high() ) ); } );

// Get the forecast for a given city using the latitude and longitude var lat = 39.100, long = -94.579; Weather.getForecastByLatLong( lat, long, function( forecast ) { console.log( 'Forecast High in Kelvin: ' + forecast.high() ); console.log( 'Forecast High in Fahrenheit' + Weather.kelvinToFahrenheit( forecast.high() ) ); console.log( 'Forecast High in Celsius' + Weather.kelvinToCelsius( forecast.high() ) ); } );

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.