node.jsrequestrequestjs

Requestjs has two different syntaxes: one as an array, one as an object


I am trying to run a script that looks like this:

const response =  await request.getAsync(channelAPI);

  let responseData = JSON.parse(response[0].body);

However, when I run this on one machine it works, whereas the other just returns the response as an object and I don't need the [0].

What is going on? I ran into this same problem before, both machines are looking at the same package.json so what is the problem?


Solution

  • Assuming you're using Bluebird, I imagine the problem is this:

    http://bluebirdjs.com/docs/new-in-bluebird-3.html

    Both promisification (Promise.promisify and Promise.promisifyAll) methods and Promise.fromCallback now by default ignore multiple arguments passed to the callback adapter and instead only the first argument is used to resolve the promise. The behavior in 2.x is to construct an array of the arguments and resolve the promise with it when more than one argument is passed to the callback adapter.

    So it would seem you have different major versions of Bluebird in your two environments.