-1

I'm struggling with some nodejs code (with this library https://github.com/gomfunkel/node-exif).

new ExifImage({image: image}, function (error, exifData) {
    if (error) {
        console.log('Error: ' + error.message);
    }

    else {
        console.log(exifData); // Do something with your data!
    }
});

My question is how to retrieve exifData outside? I don't want to embed my code inside because is pretty big. I need this to be synchronous.

Thanks.

Chris Sandvik
  • 1,787
  • 9
  • 19
CC.
  • 2,736
  • 11
  • 53
  • 70

2 Answers2

1
function handleExifData(exifData){
   // Do something with your data!
}

new ExifImage({image: image}, function (error, exifData) {
                        if (error)
                            console.log('Error: ' + error.message);

                        else 
                            handleExifData(exifData);
                    });
Ajay Ullal
  • 378
  • 2
  • 10
  • Does not really solves my problem, but I can do something with this. – CC. Dec 09 '19 at 19:08
  • I don't I completely understood the quest but you could also try using promisify from nodejs's util library. – Ajay Ullal Dec 09 '19 at 19:10
  • Later on the code, I need to build a json and one of the field is the value of the exifData. – CC. Dec 09 '19 at 19:15
  • Basically what I would like is to have var myData = getMyExifData(); Then I could do whatever I want with myData. – CC. Dec 09 '19 at 19:16
  • I would recommend you to use a combination of promisify and async await to achieve what you are trying to do. – Ajay Ullal Dec 09 '19 at 19:17
  • can you share with me something like that ? I'm a newbie in javascript (I am a Java developper and all this is unknown for me). Thanks. – CC. Dec 09 '19 at 19:53
0

Please note that Varaibles outside of the function of your callback are in scope too. You could just create a Variable above your Line with the callback and write the content to it in the callback.

You have to make sure that ypur callback is executed, before you use that variable too.

Hope this helps :)

J. Doe
  • 837
  • 1
  • 7
  • 18