I'm writing a Node.js server and I'm trying to fetch data from an API and return it to my user. I'm taking the insightlyResponse
and trying to convert to JSON. Here's my code:
insightlyResponse.setEncoding('utf8');
let rawData = '';
insightlyResponse.on('data', (chunk) => rawData += chunk);
insightlyResponse.on('end', () => {
try {
const parsedData = JSON.parse(rawData);
responseData = "PARSED";
} catch (e) {
responseData = `Got error: ${e.message}`
}
response.end(responseData);
});
The error is Got error: Unexpected token \u001f in JSON at position 0
. What does this mean and what am I doing wrong?