await search in NodeJS

Comments

2 comments

  • Avatar
    Eric Pasos

    Hi,

    Adding a catch() to handle the error will help you to see what exceptions your code is encountering. And with that, the thrown exception is because it is required to use a backtick (`) when using the variable ${folder} when concatenating it with a string value.

    For example:

    var cloudinary = require('cloudinary').v2;

    cloudinary.config({
      cloud_name: 'your_cloud_name',
      api_key: 'your_api_key',
      api_secret: 'your_api_secret',
      secure: true
    });

    const searchImages = async (folder) => {
      let promise = new Promise((resolve, reject) => {
        cloudinary.search
          .expression(`folder:${folder}`)
          .execute()
          .then((result) => { resolve(result) })
          .catch((error) => {
            console.error(error)
          });
      });

      let result = await promise; // wait until the promise resolves (*)

      return result;

      //console.log(result); // Admin API search results
    }

    searchImages('targetFolder').then((returnedValue) => {
      console.log(returnedValue);
    });
    1
    Comment actions Permalink
  • Avatar
    cdree

    thanks for the reply, without which I wasn't able to make the break through!

     

    THANKS!

     

    0
    Comment actions Permalink

Please sign in to leave a comment.