0
const https = require("https");
let url = "";

exports.handler = async function (event) {
  let rawData = "";
  const promise = new Promise(function (resolve, reject) {
    https
      .get(url, (res) => {
        res.on("data", (chunk) => {
          rawData += chunk;
        });
        res.on("end", function () {
          resolve(rawData);
        });
      })
      .on("error", (e) => {
        reject(Error(e));
      });
  });
  return promise;
};

How do I access the value of promise and console.log it?

I want to log the value of promise.

1 Answer 1

1

As your function is async you need to await the promise before returning to be able to log it within your function.

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises#async_and_await

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.