How to rewrite this async code into promise?

all the examples of using puppeter to generate pdf, official documents are written in async,await, but the node version of the project is 6.6, and async is not supported. How to change the following code to promise??

const puppeteer = require("puppeteer");
 
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto("http://www.baidu.com", {waitUntil: "networkidle2"});
  await page.pdf({
      path: "hn.pdf", 
      format: "A4"
    });
 
  await browser.close();
})();

const puppeteer = require('puppeteer');

(() => {
  puppeteer.launch().then(browser => {
    browser.newPage().then(page => {
      page.goto('http://www.baidu.com', {waitUntil: 'networkidle2'}).then(() => {
        page.pdf({
          path: 'hn.pdf',
          format: 'A4',
        }).then(() => {
          browser.close();
        });
      });
    });
  });
})();

can you try to run it? this is probably the way of thinking. Change await to Promise call

.
Menu