19.5 Writing to Files
Writing to files is similar to reading them. Here, too, the open and close methods are used to prepare access and to close the file handle after use, respectively. The fs module provides several methods of write access to files. In the first step, you’ll see the use of the write method.
You’ll also learn how you can write to a file based on a small example. For this purpose, you now need to create a logger. This is a small application or a module for larger applications that helps you write information into a file. Loggers are used in applications whenever it’s necessary to record events during operation or development for later analysis. For example, when errors occur, you can have the corresponding message written ...
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