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

154
Vistas
Node.js JavaScript retrieve callback result as variable

I'm trying to fetch the colors in an image using a module 'get-image-colors'. The module works fine.

But when I try to pass the result to a variable 'colorList', I instead get Promise { <pending> }.

Replacing return colors.map(color => color.hex()) with console.log(colors.map(color => color.hex())) prints the colors fine, but I would like to pass the results to another variable 'colorList'.

Could you please help me spot and fix the problem?


const path = require('path');
const getColors = require('get-image-colors'); // Module to get image colors

let fileName = 'color1.png';

const options = {
    count: 5,
    type: 'image/png'
}
 
let colorList = getColors(`assets/colorphotos/${fileName}`, options, function (err, colors) {
    if (err) throw err
    return colors.map(color => color.hex());
});

console.log(colorList);

about 4 years ago · Juan Pablo Isaza
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