Story points | 3 |
Tags | Node FileIO |
Hard Prerequisites | |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. | |
|
You are required to create a backend service that will help capture basic information about prospective students who come to inquire here at Umuzi. In this project, you’ll just be storing and retrieving information from plain old JSON files.
save
that saves the visitor’s data to a JSON file. The file name should be named like this visitor_{their_full_name}.json
.alice.save() # results in visitor_alice_cooper.json
bob.save() # results in visitor_bob_marley.json
charlie.save() # results in visitor_charley_sheen.json
Notice that the full name used in the file is all lower-case and spaces are replaced by underscores.
load
that takes in a name and then grabs a Visitor object from a file. It should simply console.log
the visitor.eg:
load("Alice Cooper")
// prints out all of Alice's goodies
load("Bob Marley")
// Same deal for good ol Bob
Here are some upgrades you can add to your project if you are up for it.
Update your load
function so that it returns an instance of Visitor
instead of just console.log
. You’ll need to learn a little bit about Synchronous versus Asynchronous code to get this one right :)
Make use of integer ids when saving things to files.
Update your save function so it works like this:
alice.save() # results in visitor_1.json
bob.save() # results in visitor_2.json
charlie.save() # results in visitor_3.json
alice.comments = "Kinda weird, I don't think he'll fit in"
alice.save() # results in an UPDATE to visitor_1.json
.json
files when save()
is called on a different instance.Your load function should also get a bit of an update.
charlie = load(3)
charlie.comments = "Winning!"
charlie.save() # results in an UPDATE to visitor_3.json
Imagine that the code produced by the learner needs to be maintained, imagine that some parts of the code will have to change over time. Ideally, changes to the code should be made just once, and that change should affect everything else without going through the file(s) looking to change the same thing.