File System
Learn how to use the file system to handle files.
We'll cover the following...
Using the file system module to handle files will be one of the key aspects of your build tool. Luckily, this comes out of the box with Node. You will most likely have to read in data from configuration files, write new, or update existing files.
With the projects that I have worked on, there was a configuration file in the JSON
format wherein some of the values needed to be replaced. I needed to update the ID, the date range, what service requests to call, and so on. Here is a watered-down example of a configuration file for a game campaign.
{"projectId": 234789,"game": "january-2019-wheres-wallis","startDate": "2019-01-01T00:00:00","endDate": "2019-01-08T00:00:00"}
Reading from a configuration file in JSON
When you are working on some form of template that you want to design to be configurable to the scope of your project, it is a good approach to use a separate JSON
file that contains data separated from the source code. You can obtain this data using a simple Node script.
Run the code below to read the projectId
, specified in the example-config.json
file above. Try to output the values of the other ...