Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return results #63

Open
gorbypark opened this issue Mar 25, 2017 · 1 comment
Open

Return results #63

gorbypark opened this issue Mar 25, 2017 · 1 comment

Comments

@gorbypark
Copy link

gorbypark commented Mar 25, 2017

Is it possible to return the results to a parent function? I can't seem to get exifData to return. Even if i throw something like return('test test'); as the first line after ExifImage({.... it doesn't return.

var ExifImage = require('exif').ExifImage;

function myExif() {
    try {
        new ExifImage({image: 'exif4m.jpg'}, function (error, exifData) {
            if (error) {
                console.log('Error: ' + error.message);
                return null;
            } else {
                return exifData; // Do something with your data!
            }
        });
    } catch (error) {
        console.log('Error: ' + error.message);
        return null;
    }
}

console.log(myExif());

The console.log returns undefined.

@ghost
Copy link

ghost commented Apr 7, 2017

You can solve this with a promise:

getEXIF( filePath ) {
        return new Promise(resolve => {
            ExifImage(filePath, (err, data) => {
                resolve(data);
            });
        });
    }

I call the getEXIF method on async function with await:

async function whatever() {
  // snip
  const response = await getEXIF('path to image');
  // use response here
  // snip
}

But you can of course resolve the promise traditional way. It's on you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant