0

I'm a beginner of nodejs . I have a Https api, and I use it via request-promise. How to return a global variable from this function?

Here is my code:

import rp from 'request-promise';

let options = {
    uri: `https://devapi.heweather.net/v7/warning/now?location=${cityId}&key=${apiKey}&gzip=n`
};

async function warrningApi(alert){
    let wAlert = await rp(options);
    console.log(wAlert);
    return wAlert = alert;
};

warrningApi()
  • 1
    Why should it be a global variable? – AKX Sep 21 '20 at 08:24
  • Here's the reference answer for this issue: https://stackoverflow.com/a/23667087/5734311 The short answer is that latest versions of node support an outside `await` now, so you can do this: `const weatherData = await warrningApi();` –  Sep 21 '20 at 08:28

0 Answers0