I have code that
a) handles a POST route,
b) taps API to generate access token and renders a page, and
c) runs the code on interval.
The problem is the first instance works fine, but second instance I get ERR_HTTP_HEADERS_SENT error. My code:
app.post("/intervalQuote",(req,res)=>{
MongoClient.connect(url,{ useNewUrlParser: true, useUnifiedTopology: true }, (err,db)=>{
if (err) throw err;
const dbo = db.db('ameritrade');
const ticker = req.body.ticker.toUpperCase();
function intervalTimer() {
access_token(dbo).then((access_token)=>{
quote(access_token,ticker).then((quote)=>{
res.render('quote',{result: quote});
})
})
}
intervalTimer();
setInterval(intervalTimer,10*1000);
})
})
I need to be able to run access_token, then quote functions before rendering the quote template. How can I do this on interval and reload the page? Much thanks for the help / suggestion!