There are a handful of ways you can read and write to the File System in Node.js.
We will look at readFileSync
, readFile
, and a promise based version of readFile
.
Each have there use-cases and we will discuss the pros and cons of each one. For instance readFileSync
is a blocking operation which if you were developing a web server with Node.js would be a huge problem. With this project being in the CLI for one user, this is a ok option to consider. On the other hand, readFile
is a non-blocking operation that uses promises/callbacks to interact with the file system.