Categories
JavaScript Answers

How to wait for a stream to finish piping with Node?

Spread the love

To wait for a stream to finish piping with Node, we use the stream/promises module.

For instance, we write

import * as StreamPromises from "stream/promises";

//...
await StreamPromises.pipeline(sourceStream, destinationStream);

to call StreamPromises.pipeline to pipe sourceStream to destinationStream.

We use await to wait for the promise returned to finish before proceeding.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.