Search code examples
node.jsweather-api

How to use the "Options" from the Darksky API to change the temperature from fahrenheit to celsius?


I have looked into the forecast io (Darksky) api document, and find there are options that can change the temperature to celsius. I'm not sure how to use the code they provided.

Thanks for your help!


Solution

  • You can add the si units options to your parameters in the request. This should give you back temperature in celsius. For example:

    const https = require('https');
    var body = "";
    
    const url = "https://api.darksky.net/forecast/your-key-goes-here/53.34929607,-6.26036167?units=si"
    
    var req = https.request(url, (res) => {
          res.on('data', (d) => {
          body += d;
        });
    
        res.on('end', () => {
            var data = JSON.parse(body);
            console.log(data.currently.temperature);
        });
    });
    
    req.on('error', (e) => {
      console.error(e);
    });
    
    req.end();
    

    I hope this helps.