Search code examples
node.jscurlfile-get-contents

file_get_contents() equivalent for Node.JS


I was wondering if there was any file_get_contents() equivalents in Node.JS modules or elsewhere. It has to lock the process until the download is finished, so the existing request() code in Node.js won't work. While it doesn't need to read into the string, the locking, synchronous nature is important.

If this doesn't exist, is using CURL via the OS module an efficient way of handling the same process?


Solution

  • No, there's not. Do it asynchronously: Do stuff, and when the download completes and you've buffered it all into one place, emit an event or call a callback to do the work on the whole blob.