Saving body from request.get() [duplicate]Why is my variable unaltered after I modify it inside of a function? - Asynchronous code referenceHow do I return the response from an asynchronous call?How do I remove a property from a JavaScript object?Remove empty elements from an array in JavascriptGet selected text from a drop-down list (select box) using jQueryHow do I remove a particular element from an array in JavaScript?How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)Writing a JSON file after a lot of async requestsHow do I return the response from an asynchronous call?What is the --save option for npm install?Request data to global variableWait for data from external API before making POST request

Solenoid fastest possible release - for how long should reversed polarity be applied?

"Counterexample" for the Inverse function theorem

Polynomial division: Is this trick obvious?

Would a "ring language" be possible?

How can I fix the label locations on my tikzcd diagram?

How can we delete item permanently without storing in Recycle Bin?

What formula to chose a nonlinear formula?

Given 0s on Assignments with suspected and dismissed cheating?

Do we see some Unsullied doing this in S08E05?

Promotion comes with unexpected 24/7/365 on-call

Cannot remove door knob -- totally inaccessible!

Would it be fair to use 1d30 (instead of rolling 2d20 and taking the higher die) for advantage rolls?

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

How come Arya Stark didn't burn in Game of Thrones Season 8 Episode 5

How could it be that 80% of townspeople were farmers during the Edo period in Japan?

Why would you put your input amplifier in front of your filtering for and ECG signal?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

What would a Dragon have to exhale to cause rain?

How was the blinking terminal cursor invented?

When the match time is called, does the current turn end immediately?

How does the Heat Metal spell interact with a follow-up Frostbite spell?

When did Britain learn about American independence?

Why is so much ransomware breakable?

Failing students when it might cause them economic ruin



Saving body from request.get() [duplicate]


Why is my variable unaltered after I modify it inside of a function? - Asynchronous code referenceHow do I return the response from an asynchronous call?How do I remove a property from a JavaScript object?Remove empty elements from an array in JavascriptGet selected text from a drop-down list (select box) using jQueryHow do I remove a particular element from an array in JavaScript?How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)Writing a JSON file after a lot of async requestsHow do I return the response from an asynchronous call?What is the --save option for npm install?Request data to global variableWait for data from external API before making POST request






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0
















This question already has an answer here:



  • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

    6 answers



I want to save the body from a get request in a variable (using the request module), but its undefined.



I've searched for a solution but nothing worked so far. Guess the problem is that request.get is calles async (so far i have no experience in async functions).



const request = require("request")
...
let foo;
request.get(options,function(err,response,body)
foo = body;
);
console.log(foo);


expected: the body of the valid get-request
actual: undefined










share|improve this question













marked as duplicate by Jonathan Lonowski javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 16:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























    0
















    This question already has an answer here:



    • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

      6 answers



    I want to save the body from a get request in a variable (using the request module), but its undefined.



    I've searched for a solution but nothing worked so far. Guess the problem is that request.get is calles async (so far i have no experience in async functions).



    const request = require("request")
    ...
    let foo;
    request.get(options,function(err,response,body)
    foo = body;
    );
    console.log(foo);


    expected: the body of the valid get-request
    actual: undefined










    share|improve this question













    marked as duplicate by Jonathan Lonowski javascript
    Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 23 at 16:45


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      0












      0








      0









      This question already has an answer here:



      • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

        6 answers



      I want to save the body from a get request in a variable (using the request module), but its undefined.



      I've searched for a solution but nothing worked so far. Guess the problem is that request.get is calles async (so far i have no experience in async functions).



      const request = require("request")
      ...
      let foo;
      request.get(options,function(err,response,body)
      foo = body;
      );
      console.log(foo);


      expected: the body of the valid get-request
      actual: undefined










      share|improve this question















      This question already has an answer here:



      • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

        6 answers



      I want to save the body from a get request in a variable (using the request module), but its undefined.



      I've searched for a solution but nothing worked so far. Guess the problem is that request.get is calles async (so far i have no experience in async functions).



      const request = require("request")
      ...
      let foo;
      request.get(options,function(err,response,body)
      foo = body;
      );
      console.log(foo);


      expected: the body of the valid get-request
      actual: undefined





      This question already has an answer here:



      • Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

        6 answers







      javascript node.js node-request






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 16:37









      DrSteifDrSteif

      1




      1




      marked as duplicate by Jonathan Lonowski javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 23 at 16:45


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Jonathan Lonowski javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 23 at 16:45


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The request is done in asynchronous way so your console.log happens before the request is completed, so foo is still undefined.



          You must put your console log inside the callback body. Also, any computation requiring the result from the request should be started from within the callback.



          request.get(options,function(err,response,body)
          console.log(body);
          doSomethingAfterMyRequest(body)
          );


          Also, you should handle your error, because if an error occurs during your request, it's possible that body remains undefined.



          request.get(options,function(err,response,body)
          if (err)
          console.error(err)
          return

          console.log(body);
          doSomethingAfterMyRequest(body)
          );





          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The request is done in asynchronous way so your console.log happens before the request is completed, so foo is still undefined.



            You must put your console log inside the callback body. Also, any computation requiring the result from the request should be started from within the callback.



            request.get(options,function(err,response,body)
            console.log(body);
            doSomethingAfterMyRequest(body)
            );


            Also, you should handle your error, because if an error occurs during your request, it's possible that body remains undefined.



            request.get(options,function(err,response,body)
            if (err)
            console.error(err)
            return

            console.log(body);
            doSomethingAfterMyRequest(body)
            );





            share|improve this answer



























              0














              The request is done in asynchronous way so your console.log happens before the request is completed, so foo is still undefined.



              You must put your console log inside the callback body. Also, any computation requiring the result from the request should be started from within the callback.



              request.get(options,function(err,response,body)
              console.log(body);
              doSomethingAfterMyRequest(body)
              );


              Also, you should handle your error, because if an error occurs during your request, it's possible that body remains undefined.



              request.get(options,function(err,response,body)
              if (err)
              console.error(err)
              return

              console.log(body);
              doSomethingAfterMyRequest(body)
              );





              share|improve this answer

























                0












                0








                0







                The request is done in asynchronous way so your console.log happens before the request is completed, so foo is still undefined.



                You must put your console log inside the callback body. Also, any computation requiring the result from the request should be started from within the callback.



                request.get(options,function(err,response,body)
                console.log(body);
                doSomethingAfterMyRequest(body)
                );


                Also, you should handle your error, because if an error occurs during your request, it's possible that body remains undefined.



                request.get(options,function(err,response,body)
                if (err)
                console.error(err)
                return

                console.log(body);
                doSomethingAfterMyRequest(body)
                );





                share|improve this answer













                The request is done in asynchronous way so your console.log happens before the request is completed, so foo is still undefined.



                You must put your console log inside the callback body. Also, any computation requiring the result from the request should be started from within the callback.



                request.get(options,function(err,response,body)
                console.log(body);
                doSomethingAfterMyRequest(body)
                );


                Also, you should handle your error, because if an error occurs during your request, it's possible that body remains undefined.



                request.get(options,function(err,response,body)
                if (err)
                console.error(err)
                return

                console.log(body);
                doSomethingAfterMyRequest(body)
                );






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 at 16:44









                François P.François P.

                2,115716




                2,115716















                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현