Skip to main content

await search in NodeJS

Comments

2 comments

  • 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
  • cdree

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

     

    THANKS!

     

    0

Post is closed for comments.