request / request-promise-native

The simplified HTTP request client 'request' with Promise support. Powered by native ES6 promises.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeprecationWarning when piping to createWriteStream

thany opened this issue · comments

I'm using the recommended? way to stream a request to a file, and use await to wait until I can move to downloading the next file in my queue.

const r = request(file.url);
r.pipe(fs.createWriteStream(file.target));
await r;

Simple enough. And it absolutely completely works. But, occasionally I get a warning:

DeprecationWarning: Calling an asynchronous function without callback is deprecated

Does it need a callback then? And where, what should I put into it?

Also, I'm a noob on node (expert on general javascript though) so I might not be doing it correctly. If that's the case, please do show me a correct(er) way to "just" download a binary file and wait for it.

I'm on NodeJS 7.10 and Windows 10, if that helps.

Please do not use request-promise-native for streaming the response. Use request directly.

See the request-promise README for a little more detail where it says that “STREAMING THE RESPONSE (e.g. .pipe(...)) is DISCOURAGED”.

You can use request-promise-native and request alongside in your project. Depending on what kind of request you do you can just use one or the other.

Seems wasteful to install two components that do exactly the same. Can't this issue just be fixed?

Of course. Stay tuned for the fix of the issue over on request-promise.

Btw while you wait: Technically you are already installing request. request-promise-native is just an extension that adds promise capabilities to request. request is always the library that does the actual heavy lifting.