Skip to content

Node Ecosystem Readings

Wei edited this page Mar 19, 2019 · 2 revisions

Node will assume you are interested in the binary data and will give you a Buffer object instead of a string. This is

an array-like object that contains numbers representing the bytes (8-bit chunks of data) in the files. const {readFile} = require("fs"); readFile("file.txt", (error, buffer) => { if (error) throw error; console.log("The file contained", buffer.length, "bytes.", "The first byte is:", buffer[0]); });

Clone this wiki locally