The readFile
function reads the entire content of the file asynchronously and stores it in the memory before passing it to the user.
createReadStream
uses a readable stream that would read the file chunk by chunk without storing the entirety of it into the memory.
createReadStream
optimizes the file reading operation compared to readFile
by using less memory and making it faster. If the file is of considerable size, the user doesn’t have to wait a long time until its entire content is available, because small chunks are sent to the user as they are read.