File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
Expand file tree Collapse file tree 3 files changed +44
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' )
2+
3+ const APPID = '' // <-- Put your OpenWeatherMap appid here!
4+ const URL_BASE = 'http://api.openweathermap.org/data/2.5/'
5+
6+ async function currentWeather ( location ) {
7+ const response = await fetch ( `${ URL_BASE } weather?q=${ location } &appid=${ APPID } ` )
8+ const data = await response . json ( )
9+ return data
10+ }
11+
12+ async function weatherForecast ( location ) {
13+ const response = await fetch ( `${ URL_BASE } forecast?q=${ location } &appid=${ APPID } ` )
14+ const data = await response . json ( )
15+ return data
16+ }
17+
18+ async function oneCallApi ( latitude , longitude ) {
19+ const response = await fetch ( `${ URL_BASE } onecall?lat=${ latitude } &lon=${ longitude } &appid=${ APPID } ` )
20+ const data = await response . json ( )
21+ return data
22+ }
23+
24+ currentWeather ( 'Kolkata' )
25+ . then ( data => console . log ( data ) )
26+
27+ weatherForecast ( 'Kolkata' )
28+ . then ( data => console . log ( data ) )
29+
30+ oneCallApi ( 55.68 , 12.57 )
31+ . then ( data => console . log ( data ) )
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " javascript" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " A repository for All algorithms implemented in Javascript (for educational purposes only)" ,
5+ "scripts" : {
6+ "test" : " echo \" Error: no test specified\" && exit 1"
7+ },
8+ "author" : " TheAlgorithms" ,
9+ "license" : " GPL-3.0" ,
10+ "dependencies" : {
11+ "node-fetch" : " 2.6.0"
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments