Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!