Retaining the State
Explore how to maintain and persist state data in Node.js command-line applications by using hidden dot-files instead of browser storage. Understand techniques like sharing constants, reading and writing JSON reminder files, and interacting with users to add or remove reminders. This lesson guides you through creating scripts that manage persistent reminders, helping automate tasks efficiently.
We'll cover the following...
When you are dealing with the process of a script, and it exists, then all the data or the state is forgotten. So, what should you do if you need to retain this state? When you are in a browser, you can use something like local storage or cookies, but you do not have this with a CLI application. Instead of using local storage or cookies, you can create hidden files or dot-files to retain, or persist, your data. In Unix-like systems, files prefixed with a dot are hidden by default, which is why they are called dot-files.
A great example to demonstrate this would be to store some reminders. You will have one script that adds a reminder and one that lists the reminders. You will ensure that you have .reminders.json present. If not, you will run node setup.js in the root of the nobot-examples repository. For ...