C
C
Concordeair2022-04-19 20:31:31
JavaScript
Concordeair, 2022-04-19 20:31:31

Getting a specific variable from a Node.js get request?

I'm just learning and I can somehow express myself incorrectly, but I hope you understand me and help.

There is a curl request:
curl -X GET "url" -H "accept: text/plain"
Which I remade into a Node.js request:

var request = require('request');

var headers = {
    'accept': 'text/plain'
};

var options = {
    url: 'url',
    headers: headers
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);


From this request, I get a response:
{"countries":[{"countryId":643,"countryCode":"ru","unitId":395,"date":"2022-04-18T00:00:00","stationaryRevenue":63453.00,"stationaryOrderCount":151,"deliveryRevenue":141308.00,"deliveryOrderCount":107,"revenue":204761.00,"orderCount":258,"avgCheck":793.6472868217054263565891473}],"errors":[]}


How do I write code that only emits a specific variable like "revenue" ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ne7Le4Der, 2022-04-19
@Concordeair

https://codepen.io/Ne7Le4DeR/pen/rNpPyop
If I understand correctly. Option with forEach - if all are needed, lower option - if a specific index is needed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question