Home > OS >  Getting error while Retrieving data from Google BooksAPI. Can someone tell why it's showing und
Getting error while Retrieving data from Google BooksAPI. Can someone tell why it's showing und

Time:06-23

I am running this one express server.

While trying to console log get items data from the API it's showing undefined

CodePudding user response:

You haven't parsed the data, therefore it is only a string, with no properties (.items). If it's JSON, you'll need to run it through JSON.parse(...), and then try to access it. If that doesn't work, it's probably in a wrong format, I recommend logging just data, and see what it is.

CodePudding user response:

Your are getting chunks of data with this handler:

let data = '';
      resp.on('data', (chunk) => {
            data  = chunk;
          });

After all chunks are fetched, you simply call:

resp.on('end', () => {
    console.log(data);
  });
  • Related