title: Send a set-cookie header to a redirect url in node.js
body: <p>I am using node.js <code>request</code> module to fetch an id_token from an API. After fetching that id_token I want to send a <code>redirect uri</code> response with a <code>set-cookie header to the redirected url</code>. But I can't quite figure out how to do it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>app.use("/nodejs-server/retrieveCode", function(req, res) {
  
          var clientID = 'some random string'
          var client_Secret = 'another random string'
          var code_token = clientID + ":" + client_Secret
          var buffer = new Buffer(code_token)
          var token = buffer.toString('base64')
          var rtoken = "Basic " + token;
          var headers = {
              'Content-Type': 'application/json',
              'Authorization': rtoken
          }
          var postData = {grant_type: 'authorization_code', code: req.query.code, redirect_uri: 'http://localhost:3000/nodejs-server/retrieveCode'} //Query string data
          var options  = {
              method: 'POST', //Specify the method
              body: postData,
              url: 'http://localhost:4000/server/token',
              json: true,
              headers: headers
          }
          request(options
          , function(error, response, body){
              if(error) {
                  console.log(error);
              } else {
                  //send a redirect uri and set-cookie header response
  
              }
          });
  </code></pre>
  
  <p>I tried using </p>
  
  <pre><code>res.redirect(302, "http://localhost:9000");
  </code></pre>
  
  <p>and it is able to redirect but I am not able to send the cookie with it as well</p>
  
  <p>Any help is appreciated.</p>