Simple APIs to use with OpenWeatherMap.org free servicies, request a APPID on http://openweathermap.org/appid and start!
Simple abstraction layer for use the services offered by the OpenWeatherMap.org website through its API's. You can easy reach the weather informations you need on over 400k weather stations. For get the APPID follow the OpenWeather.org link and complete the request process.
Main changes by version (if the first number change, old code you have written is not supported, for example between version 1.x.x to version 2.x.x (I apologize for that):
- First version
- Version 1.2.0 minor bugs fix
- Version 2.0.0 link in the callback for the operational error such as the ClientRequest, HTTPParse and so on ...
- Version 2.0.1 minor fix (no code impact)
- Version 2.0.2 important fix - encodeURIComponent for city name, Unexpected token handled as error
- Version 2.0.3 minor fix (no code impact)
- Version 2.1.0 minor fix (no code impact)
- Version 2.1.5 minor fix (no code impact)
- Version 3.0.0 Removed ResponseCode function (useless)
- Version 3.3.0 get the rain in present in getSmartJSON
- Version 4.0.0 Fix unhandled exception #26
- Version 4.1.0 Add ssl support (default: false) & use querystring.stringify() for path Thanks https://github.com/Ti-Tom
- Version 4.2.0 Minor Fix Pull request #31 Thanks https://github.com/mikedidomizio
Like all node packages, install and mange operation are done by npm (use the -s if you want save the package in the package.json file) :
npm install openweather-apis// install and save in package.jsonnpm install openweather-apis --save// global installationnpm install -g openweather-apis
How to Use
Install the package with npm, import with the require statement in the app, and start to use the apis. First step is set the params for the request (request the api-key at http://openweathermap.org/register ):
var weather = ;weather;// English - en, Russian - ru, Italian - it, Spanish - es (or sp),// Ukrainian - uk (or ua), German - de, Portuguese - pt,Romanian - ro,// Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg,// Swedish - sv (or se), Chinese Tra - zh_tw, Chinese Sim - zh (or zh_cn),// Turkish - tr, Croatian - hr, Catalan - ca// set city by nameweather;// or set the coordinates (latitude,longitude)weather;// or set city by ID (recommended by OpenWeatherMap)weather;// or set zip codeweather;// 'metric' 'internal' 'imperial'weather;// check for get the APPIDweather;
Current Weather Data
Using the following requests to API, you can get current weather data for any location on the Earth. Current weather data are updated in real time based on data from global weather providers and more than 40,000 weather stations. Weather data is available in JSON.
Import the module and start to use the functions :
// get the Temperatureweather;// get the Atm Pressureweather;// get the Humidityweather;// get the Description of the weather conditionweather;// get all the JSON file returned from server (rich of info)weather;
This function returns a complete openweathermap.org json object :
// get 3 days forecastweather;// get a simple JSON Object with temperature, humidity, pressure and descriptionweather;
This is the simple JSON object returned by the getSmartJSON(), pretty useful ! The rain value can be zero if not measured or a mesured value.
temp : 25humidity : 88pressure : 101325description : 'sun'rain: 4weathercode : 200
this JSON object is easy to use and is enough for a lot of possible use of the weather data, for example the weathercode is easy to use for build check function, draw the icons ecc, for the complete table about this code go to this link on official [docs].
Yes, of course you can set the location to get info by the coordinates, first the latitude, second the longitude. Sometimes use the coordinates are worse than the city name !
Use the callback to check if an error is raised on the request (HTTP server unreachable or other connection, request problem), you need to handle the error on the request, for example :
The package is tested with mocha and chai. You can find the tests in the /test folder. If you need to use more tests on the library, open an issue on the github repo (THANKS).