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

382
Views
Cannot read property '0' of undefined

I'm getting a weird undefined error when I'm triying to use pkgcloud and also the property length is undefined :

var pkgcloud = require('pkgcloud');
var Q = require('q');
router.get('/', function(req, res, next) {

var conn = pkgcloud.compute.createClient({
    provider: 'openstack', // required
    username: 'demo', // required
    password: 'azerty', // required
    authUrl: 'http://192.168.0.242:5000' ,
    region_name :'RegionOne'// required
});
console.log(conn);

At this stage I can visualize the different methods of the object conn, but the error is generated within the for loop:

var d = Q.defer();
conn.getImages(function(err, images) {

    for (var i=0; i<images.length; i++) {
        console.log("id: " + images[i].id);
        console.log("name: " + images[i].name);
        console.log("created: " + images[i].created);
        console.log("updated: " + images[i].updated);
        console.log("status: " + images[i].status + "\n");
    }
    if (err) {
        console.log("erreur");
        d.reject(err);
    } else {
        console.log("juste");
        d.resolve();
    }
});
  res.render('index', { title: 'Express' });
});
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you are receiving array of objects please consider using console.table(); - that will save your time. As everyone said do the error check first then if no error print output. I don't know if SO will render table in snippet so please check your browser's console for table output.

const img = [{
  id: 1,
  name: "cat",
  created: '21-07-99',
  updated: '21-07-99',
  status: "new"
}, {
  id: 2,
  name: "dog",
  created: '26-07-00',
  updated: '26-07-00',
  status: "new"
}, {
  id: 3,
  name: "rabbit",
  created: '16-02-10',
  updated: '26-04-10',
  status: "modified"
}];

con = (err, image) => {
  if (err) {
    console.log("ERROR", err);
    return;
  }
    console.table(image);
 
};
con("404 not found",img); //error 404 will print err
con(null, img); //no error so img

over 4 years ago · Santiago Trujillo Report
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!