Question: need a help to create javascript functions..... initialize() This function will read the contents of the ./data/employees.json file ( hint : see the fs module
need a help to create javascript functions.....
initialize()
- This function will read the contents of the "./data/employees.json" file (hint: see the fs module & the fs.readFile method), convert the file's contents into an array of objects (hint: see JSON.parse) , and assign that array to the employees array (from above).
- Only once the read operation for "./data/employees.json" has completed successfully (not before), repeat the process for the "./data/departments.json" and assign the parsed object array to the departments array from above.
- Once these two operations have finished successfully, invoke the resolve method for the promise to communicate back to server.js that the operation was a success.
- If there was an error at any time during this process, invoke the reject method for the promise and pass an appropriate message, ie: reject("unable to read file").
getAllEmployees()
- This function will provide the full array of "employee" objects using the resolve method of the returned promise.
- If for some reason, the length of the array is 0 (no results returned), this function must invoke the reject method and pass a meaningful message, ie: "no results returned".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
