Node Js Simple Weather App Using Darksky API - Node Js Tutorial

July 31, 2019

Hi, after coping with my real life and those 'tiring' daily activities, finally I can write again.
in this tutorial I will share with you guys how to access darksky api using node js.

Node Js Simple Weather App Using Darksky API, weather app node js, node js darksky, darksky api, node js weather app simple
Node Js Simple Weather App Using Darksky API 

Node Js Simple Weather App Using Darksky API 

What module we need to accees ?

as we are going to access the API from other site and make http request, a module called request is needed. What is request module for node js ? according to stackabuse.com,  The request module is by far the most popular (non-standard) Node package for making HTTP requests. It means that HTTP requests with Node.js are a means for fetching data from a remote source. It could be an API, a website, or something else: at one point you will need some code to get meaningful data from one of those remote sources - valentinog.com.

And what is Darksky API ?

Darksky API is one of API provider for weather forecast. Why Darksky API ? because its it can be configured easily in minutes, developer friendly, clear and concise documentation. It also provides forecasts and current conditions, global coverage, historical data, and severe weather alerts

Here is the example of Node Js Simple Weather App Using Darksky API


const request = require('request')

const url = 'https://api.darksky.net/forecast/8593f986c0f88727f3270a097ee4b90c/37.8267,-122.4233?units=si'
//'https://api.darksky.net/forecast/8593f986c0f88727f3270a097ee4b90c/37.8267,-122.4233' to customize add ? followed with the keyvalue=value
//example 'https://api.darksky.net/forecast/8593f986c0f88727f3270a097ee4b90c/37.8267,-122.4233?units=si&ang=id'
//read https://darksky.net/dev/docs

const getWeather = () => {
    request({ url: url, json: true }, (error, response) => { //json true to enable automatic json parsing
        // const data = JSON.parse(response.body) // it is used if json option is not enabled / json: not true ..which is to change json string to json
        // console.log(response.body)
        console.log(`overall, the weather today is ${response.body.currently.summary} with the temperature of ${response.body.currently.temperature} celcius `)
        console.log(`and right now is ${response.body.minutely.summary} .. and current precip intensity is ${response.body.minutely.data[0].precipIntensity}`)
    })
}

getWeather()



you can see in my github for more:

I hope it can be useful for you :)

Tag: Node Js Simple Weather App Using Darksky API, weather app node js, node js darksky, darksky api, node js weather app simple

Share this

Related Posts

Previous
Next Post »