Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
canvas.toDataURL() returns [object Promise]

Can someone please tell me why canvas.toDataURL() shows [object Promise]? I want to load a node-canvas image on my website with an image tag in HTML. Here is my code:

Handlebars.registerHelper('updateImage', async function (id, user) {
    const welcome = new Keyv(`sqlite://data/welcome/${id}.sqlite`);
    const bgimg = await welcome.get('canvas-join-bgimg') ? await welcome.get('canvas-join-bgimg') : `https://i.imgur.com/XMPcnz1.jpeg`;

    const Canvas = require('canvas');

    const background = await Canvas.loadImage(bgimg);
    const avatardash = await Canvas.loadImage(user.displayAvatarURL({
        dynamic: true,
        size: 1024
    }));

    const canvas = Canvas.createCanvas(700, 250);
    const context = canvas.getContext('2d');

    context.drawImage(background, 0, 0, canvas.width, canvas.height);

    return new Handlebars.SafeString(
        '<img src='
        ' + canvas.toDataURL() + '
        ' />'
    );
});

Sorry, but I'm still learning, and I do not see anything of this on the web.

EDIT: Here you can see the result on my website:

Result

Any assistance would be greatly appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is because you have not yet awaited the promise, therefore the promise is unresolved.

Awaiting the promise is simple, simply add the await keyword:

return new Handlebars.SafeString(
  `<img src="${await canvas.toDataURL()}">`
);

The above code is awaiting the promise and using template literals to avoid string concatenation.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda