I am trying to build a dynamic song list, everyday users get a fresh song list from the server using REST call, and then that list will get updated to a local file, which will use that data for day’s duration. I am not sure if we can override the file, I tried using the below code, while I am able to get rest data with HTTP, HTTPS doesn’t work. Could you please guide me if its a better approach or not and also how to handle HTTPS calls.
async function getSongsList() {
// Do API call and return data
const options = {
// uri: 'https://drive.google.com/open?id=1t40Kwlcf2iFJ5vNNFDfrOz8jQ_iriR6x',
// uri: 'http://padmainterior.co.in/tirthankar/songs/songlist.txt',
uri: 'http://swquotesapi.digitaljedi.dk/api/SWQuote/RandomStarWarsQuoteFromFaction/4',
json: true // Automatically parses the JSON string in the response
};
const data = await requestPromise(options);
const songdata = data.starWarsQuote;
// fs.writeFileSync("./input/pravchan.json",songdata,{encoding:'utf8',flag:'w'});
try {
fs.writeFileSync("./input/pravchan.json", songdata)
} catch (err) {
console.error(err)
}
}
// return quote;