title: Node Request inside request with cookie
body: <p>I am using node request <code>var request = require(“request”);</code> in my config node to do a POST request and in response get a Cookie which need to be referred in all rest of requests. </p>
  
  <p>I tried enabling COOKIE JAR that works fine if i chain my request under first request but I want to call rest of requests like GetList from custom node.</p>
  
  <p>I tried toughcookie (file cookie) not working when i add <code>var j = request.jar(new FileCookieStore(‘cookies.json’))</code>;
    node stop working with no error.</p>
  
  <p>Below is my config node, code using which I am getting Cookie. </p>
  
  <pre><code>function myAuthNode(n) {
  
          RED.nodes.createNode(this,n);
          this.username=n.username;
          this.password=n.password;
  
  
              this.connect=function(){
                  //TODO-NG need to make URL configurable
                  request.post({url: "http://localhost:8080/api/method/login", qs: {usr: this.username, pwd: this.password}}, function(err, res, body) {
  
                      if(err) {
                              return console.error(err);
                      }
  
                      console.log("HERE IF I PUT REQUEST Works fine");
                      console.log("CAN WE PASS ANOTHER REQUEST here from calling SOURCE to execute here?");
  
                  });
  
          };
  
  
  
      }
  </code></pre>
  
  <p>Here in this custom node I am calling</p>
  
  <pre><code> // The main node definition - most things happen in here
      function GetListNode(n) {
          // Create a RED node
          RED.nodes.createNode(this,n);
          console.log('I am called');
  
          //using auth config now you are connected, tell me what is needed?
          this.authConfig=RED.nodes.getNode(n.auth);
          //connect to config and do auth
  
          this.authConfig.connect();
  
  //THIS ALWAYS FAILS due to cookie not found where as I enable request JAR
  
         request.get({url: "http://localhost:8080/api/resource/Project"}, function(err, res, body) {
  
                  if(err) {
                          return console.error(err);
                  }
  
                      console.log("Response body:", body);
  
              });
  
  
      }
  </code></pre>
  
  <p>Please suggest how to handle cookie in request so that all requests after auth works fine? </p>
  
  <p>Can we pass a request definition to another request for execution inside it or how Cookie can be handled ?</p>