I am attempting to access underlying data from an API call, bust cannot access the data in handlebars. If I use {{results}} the raw data is produced, but I can’t figure out how to produce the data in handlebars on the rendered view.
Here is the rendered data:
[
{
"symbol": "AAPL",
"name": "Apple Inc.",
"price": 183.38,
"changesPercentage": 5.9816,
"change": 10.35,
"dayLow": 182.66,
"dayHigh": 187,
"yearHigh": 199.62,
"yearLow": 164.08,
"marketCap": 2831735622000,
"priceAvg50": 172.4082,
"priceAvg200": 181.24574,
"exchange": "NASDAQ",
"volume": 157741757,
"avgVolume": 61436927,
"open": 186.67,
"previousClose": 173.03,
"eps": 6.44,
"pe": 28.48,
"earningsAnnouncement": "2024-08-01T04:00:00.000+0000",
"sharesOutstanding": 15441900000,
"timestamp": 1714766407
}
]
router.post('/quote', function (req, res, next) {
var homeUrl = 'https://financialmodelingprep.com/api/v3/quote/'
var symbol = req.body.search
var apiKey = '?apikey=scoijsjdlkjc'
var fullUrl = homeUrl + symbol + apiKey;
request(fullUrl, function (error, response, stock) {
if (!error && response.statusCode == 200) {
fs.writeFile('data/quotes/' + symbol + ".json", results, function (err) {
console.log({results: stock})
console.log("The file was saved as " + symbol + ".json");
res.render('quoteresults', results)
if (err) {
return console.log(err);
}
});
}
});
});