Sever Action Output Timing

I have a set of server actions running and created a custom module (with an output) that uploads a file to a new folder…

How do I ensure the file is there before moving to the next server action?

Currently putting a wait time of 10 seconds for example works but would like the code to run as soon as possible rather than an set time later.

response.data.pipe(fs.createWriteStream(destinationImagePath))
    .on('error', (err) => { return err, console.log(err) })
    .once('close', () => { return true, console.log('Success') });

if (response.err == true) {
    return ('Error');
} else {
    return ('Success');
};

Community Page
Last updated: