19.3 Reading Files
In Node.js, you have several ways to read the contents of a file. Let’s first take a look at the classic way. With this method, you create a file handle in the first step, use it to read the file, and then close the file handle again. If you already have experience in programming with other programming languages such as C or PHP, this type of file access will look familiar to you.
The use of the different operations that help you to read files will be described in the following sections based on a concrete example. The application is intended to read a configuration file whose content is in JavaScript Object Notation (JSON) format. You pass the configParser the environment for which you want to read the configuration and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access