Export async config module node.js

In my project i want to use puppeteer and share it across multiple files. I want to store it as config file where i can export it and get my page variable. Problem with that is when I am importing that by require() it returns a me promise with status pending. What is then the solve?

// configFile.js
const puppeteer = require('puppeteer');

module.exports = (async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  return page;
})();
const page = require('./configFile'); // Promise { <pending> }

How to resolve that promise before it can be exported? Is there an await for module.exports?

62 thoughts on “Export async config module node.js”

  1. 512813 596317You completed several excellent points there. I did specific searches on the issue and located many men and women go in conjunction with along together with your weblog. 80181

    Reply

Leave a Comment