'Resolve export chain of async modules [duplicate]

Q) What am I missing? I always get RequestA undefined. I've a main.js that loads index.js.

  1. index.js
const { RequestA } = require('./async-module-1');

module.exports = {
  RequestA,
};

This module loads another async module async-module-2.js.

  1. async-module-1.js
// Requires another async module

const { async-fun-1 } = require('async-module-2');

module.exports = (async function () {
  
  // Util function to return base64 of any image
  const async-res-1 = await async-fun-1('http://localhost/TEST/Test-1.png');
  
  const RequestH = {
    image: {
      data: async-res-1,
    }
  };

  return RequestH;
})();
  1. async-module-2.js
// Makes GET requests using Axios

const encodeImage = async (url) => {
  return axios
    .get(url, {
      responseType: 'arraybuffer',
    })
    .then((response) => {
      return Buffer.from(response.data, 'binary').toString('base64');
    })
    .catch((err) => {
      logger.error(err);
    });
};

module.exports = {
  encodeImage
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source