Tips & Tutorials – Node JS

5 Ways To Read Files In NodeJS (To String, Line-by-Line, Array)

Welcome to a quick tutorial and examples on how to read files in NodeJS. Reading files, just how difficult can it be? Well, brace yourselves. It’s not that straightforward apparently. The common ways to read files in NodeJS are: To read the entire file into a string asynchronously – require(“fs”).readFile(“FILE.TXT”, “utf8”, (err, data) => { …

5 Ways To Read Files In NodeJS (To String, Line-by-Line, Array) Read More »

Write Files In NodeJS (Very Simple Examples)

Welcome to a quick tutorial and examples on how to write files in NodeJS. Want to create, write, and append to files in NodeJS? Things are a little bit confusing for beginners in NodeJS. There are 2 general ways to write files in NodeJS – Asynchronous and synchronous. To write files asynchronously: require(“fs”).writeFile(“MY.TXT”, “TEXT”); require(“fs”).appendFile(“MY.TXT”, …

Write Files In NodeJS (Very Simple Examples) Read More »