How to solve the error that util.pump in Node.js is not a function

Know how to solveutil.pump is not a functionErrors that may occur when trying to run old Node code

If you encounter the error "util.pump is not a function" when running a Node.js application or Node.js code snippet, it is because the application code is too old for the current Node.js runtime.

Thispump()The methods provided by Node.js are readablestreamUse the following syntax to write it to a writable stream:

util.pump(readableStream, writableStream)

This method has now disappeared and is not recommended for a long time, and it was removed when Node.js 6.0 was released in April 2016.

Fortunately, solving this problem is easy.

Replace the above syntax with:

const { pipeline } = require('stream')

//… pipeline(readableStream, writableStream, () => {})

The third parameter is the callback function that will be called after the pipeline is completed.

Read morepipelineHere.

Download mine for freeNode.js manual


More node tutorials: