Simple APIs to use with OpenWeatherMap.org free servicies, request a APPID on http://openweathermap.org/appid and start!
npm install openweather-apisv4.5.0 - 16-05-2023
Simple APIs to use with OpenWeatherMap.org free servicies, request a APPID on http://openweathermap.org/appid and start!
Latest (Module) version of the package (Node.js > 16) can be found at the new package domain @cicciosgamino/openweather-apis
CHANGELOG.md
``javascript
npm install openweather-apis
// install and save in package.json
npm install openweather-apis --save
// global installation
npm install -g openweather-apis
`
`javascript
var weather = require('openweather-apis')
weather.setLang('it')
// 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 name
weather.setCity('Fairplay')
// or set the coordinates (latitude,longitude)
weather.setCoordinate(50.0467656, 20.0048731)
// or set city by ID (recommended by OpenWeatherMap)
weather.setCityId(4367872)
// or set zip code
weather.setZipCode(33615)
// 'metric' 'internal' 'imperial'
weather.setUnits('metric')
// check http://openweathermap.org/appid#get for get the APPID
weather.setAPPID(ownKey)
`
`javascript
// get the Temperature
weather.getTemperature(function(err, temp){
console.log(temp)
})
// get the Atm Pressure
weather.getPressure(function(err, pres){
console.log(pres)
})
// get the Humidity
weather.getHumidity(function(err, hum){
console.log(hum)
})
// get the Description of the weather condition
weather.getDescription(function(err, desc){
console.log(desc)
})
// get all the JSON file returned from server (rich of info)
weather.getAllWeather(function(err, JSONObj){
console.log(JSONObj)
})
// Adds support for the onecall api endpoint.
weather.getWeatherOneCall = function(err, data){
}
`
This function returns a complete openweathermap.org json object:
`json`
{
"coord":{
"lon":139,
"lat":35
},
"sys":{
"country":"JP",
"sunrise":1369769524,
"sunset":1369821049
},
"weather":[
{
"id":804,
"main":"clouds",
"description":"overcast clouds",
"icon":"04n"
}
],
"main":{
"temp":289.5,
"humidity":89,
"pressure":1013,
"temp_min":287.04,
"temp_max":292.04
},
"wind":{
"speed":7.31,
"deg":187.002
},
"rain":{
"3h":0
},
"clouds":{
"all":92
},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200
}
`javascript
// get 3 days forecast
weather.getWeatherForecastForDays(3, function(err, obj){
console.log(obj)
})
// get a simple JSON Object with temperature, humidity, pressure and description
weather.getSmartJSON(function(err, smart){
console.log(smart)
})
`
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.
`javascript`
{
temp : 25,
humidity : 88,
pressure : 101325,
description : 'sun',
rain: 4,
weathercode : 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][1].
`javascript`
weather.setCoordinate(50.0467656, 20.0048731)
`javascript
weather.getTemperature(function(err, temp){
if(err) console.log(err)
// normal execution with no error
})
``
Made 🧑💻 by @cicciosgamino
[3]:http://openweathermap.org/appid