title: Can I return or resolve a promise in a .then in javascript
body: <p>I want the wrapping function to return the value in the .then inside of it, so I can use it later on.</p>
  <p>I have the following code where I first have a request function that returns a promise, then I have the statusCurrent function wrapper that sits around it and calls the request function. I am able to get the value in the .then of the request, but I need to return it in the status Current function. I have tried many a solution and am stuck.</p>
  <p>its the very end where I am consoling data which I am stuck at.</p>
  <p>Here is my code. I am not very familiar with promises, so any help would be greatly appreciated.</p>
  <pre><code>function request(opts) {
    return new Promise(function (resolve, reject) {
      https
        .request(opts, function (res) {
          res.pipe(process.stdout);
          res.setEncoding(&quot;utf8&quot;);
          let body = &quot;&quot;;
          res.on(&quot;data&quot;, (chunk) =&gt; (body += chunk));
          res.on(&quot;end&quot;, () =&gt; {
            //console.log(&quot;test1&quot;)
            //console.log(body);
            let json = JSON.parse(body);
            test = json.state;
            //console.log(&quot;test&quot;)
            resolve(json.state);
          });
        })
        .end(opts.body || &quot;&quot;);
    });
  }
  
  function statusCurrent() {
    return new Promise(function (resolve, reject) {
      request(
        aws4.sign(
          {
            hostname: &quot;-ats.iot.us-east-1.amazonaws.com&quot;,
            service: &quot;iotdata&quot;,
            region: &quot;us-east-1&quot;,
            method: &quot;GET&quot;,
            path: &quot;/things/esp8266_7F3B95/shadow&quot;,
            headers: {
              &quot;Content-Type&quot;: &quot;application/json0&quot;,
            },
          },
          {
            secretAccessKey: &quot;&quot;,
            accessKeyId: &quot;&quot;,
          }
        )
      ).then(function (val) {
        //console.log(&quot;val&quot;)
        //console.log(val)
        // THIS CONSOLES THE VALUE CORRECTLY
        resolve(val);
      });
    });
  }
  
  const LaunchRequestHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === &quot;LaunchRequest&quot;;
    },
    handle(handlerInput) {
      const speakOutput = `You're current status is`;
  
      statusCurrent().then(function (data) {
        console.log(data);
        //THIS CURRENTLY CONSOLES NOTHING
        console.log(&quot;data&quot;);
      });
  
      return handlerInput.responseBuilder.speak(speakOutput).getResponse();
    },
  };
  
  
  </code></pre>