This is very confusing as seen in #12974 or #12906. My suggestion would be "legacy."
var canvasFactory = new NodeCanvasFactory();
      var canvasAndContext = canvasFactory.create(
        viewport.width,
        viewport.height
      );
      var renderContext = {
        canvasContext: canvasAndContext.context,
        viewport,
        canvasFactory,
      };
      var renderTask = page.render(renderContext);
      renderTask.promise.then(function () {
        
        var image = canvasAndContext.canvas.toBuffer();
        fs.writeFile("output.png", image, function (error) {
          if (error) {
            console.error("Error: " + error);
          } else {
            console.log(
              "Finished converting first page of PDF file to a PNG image."
            );
          }
        });
      });
    });
  })
  .catch(function (reason) {
    console.log(reason);
  });