Chapter 2: Asynchronous JavaScript
Activity 2 – Using Async/Await
You have been tasked with building a server that interfaces with a database. You must write some code to look up sets and look up basic user objects in the database. Import the simple_db.js
file. Using the get
and insert
commands, write the following program using the async/await syntax:
- Look up the key called
john
, the keysam
, and your first name as a database key. - If the database entry exists, log the
age
field of the result object. - If your name does not exist in the database, insert your name and associate an object containing your first name, last name, and age. Look up the new data association and log the age.
For any db.get
operation that fails, save the key into an array. At the end of the program, print the keys that failed.
DB API:
db.get( index ):
This takes in an index and returns a promise. The promise is fulfilled with the db
entry associated with that...