There is no error for this code, but once I implement setInterval , this occurs
*Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
*Error: Route.get() requires a callback function but got a [object Undefined]
module.exports.readDataFavoriot = async(req,res)=>{
var options = { method: 'GET',
url: '-',
headers:
{ 'cache-control': 'no-cache',
'content-type': 'application/json',
'apikey': '-' }
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
const parsedBody = JSON.parse(body);
const results = parsedBody.results;
let formattedResults = '';
results.forEach(result => {
formattedResults += `Timestamp: ${formatTimestamp(result.timestamp)}n`;
formattedResults += `Data: ${JSON.stringify(result.data)}n`;
formattedResults += 'n'; // Add spacing between each result
});
console.log(formattedResults);
/*res.send() function in Express does not interpret
newline characters (n) by default. */
res.render('crud/favoriot2', {formattedResults})
});
}