I am using an API for some information to display on my web page using https.get() in nodejs. But when I try to console log the response by parsing it as JSON this error is shown
SyntaxError: Unexpected end of JSON input at JSON.parse () at IncomingMessage. (C:\Users\Hardik Aggarwal\Desktop\RSC\app.js:17:33) at IncomingMessage.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at IncomingMessage.Readable.push (_stream_readable.js:212:10)
at HTTPParser.parserOnBody (_http_common.js:132:24) at TLSSocket.socketOnData (_http_client.js:469:22) at TLSSocket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12)
The URL is sending the correct data in JSON format. The only problem is that JSON.parse() is not working on this data. The code is
app.get("/", function(req, res){
https.get(url, "JSON", function(response){
response.on("data", function(data){
const currency=JSON.parse(data);
console.log(currency);
})
})
res.render("index");
})