Buffer entire file in memory with NodeJs
问题 I have a relatevely small file (some hundreds of kilobytes) that I want to be in memory for direct access for the entire execution of the code. I don't know exactly the internals of NodeJs, so I'm asking if a fs open is enough or I have to read all file and copy to a Buffer ? 回答1: Basically, you need to use the readFile or readFileSync function from the fs module. They return the complete content of the given file, but differ in their behavior (asynchronous versus synchronous). If blocking