This function will provide the full array of department objects using the resolve method of the returned
Question:
This function will provide the full array of "department 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, le: "no results returned".
Step 5: Updating the code surrounding app.listen)
Before we start updating the routes in server is to use our new data-service module, we must make a small update to the code surrounding the app.listen() call at the bottom of the server.js file. This is where the initialize() method from our data-service.js module comes into play.
Fundamentally, initialize() is responsible for reading the son files from the "data" folder and parsing the results to create the "global" (to the module) arrays, "employees" and "departments" that are used by the other functions. However, it also returns a promise that will only resolve successfully once the files were read correctly and the "employees" and "departments" arrays were correctly loaded with the data
Similarly, the promise will reject if any error occurred during the process. Therefore, we must only call
app.listen() if our call to the initialize() method is successful, le: .then(() (//start the server )).
If the initialize() method invoked reject, then we should not start the server (since there will be no data to
fetch) and instead a meaningful error message should be sent to the console, le: .catch()=>{/"output the
error to the console /11 [21:58, 1/31/2022] Gold Port: Assume the training feature matrix X is a (p+1)*N matrix, where p is the number of predictors and N is the sample size of training data, and p>N. Assume X is of full rank, i.e. rank(X)=r=N
[02:08, 1/31/2022] Gold Port: This function will provide the full array of "department 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, le: "no results returned".
Step 5: Updating the code surrounding app.listen)
Before we start updating the routes in server is to use our new data-service module, we must make a small update to the code surrounding the app.listen() call at the bottom of the server.js file. This is where the initialize() method from our data-service.js module comes into play.
Fundamentally, initialize() is responsible for reading the son files from the "data" folder and parsing the results to create the "global" (to the module) arrays, "employees" and "departments" that are used by the other functions. However, it also returns a promise that will only resolve successfully once the files were read correctly and the "employees" and "departments" arrays were correctly loaded with the data
Similarly, the promise will reject if any error occurred during the process. Therefore, we must only call
app.listen() if our call to the initialize() method is successful, le: .then(() (//start the server )).
If the initialize() method invoked reject, then we should not start the server (since there will be no data to
fetch) and instead a meaningful error message should be sent to the console, le: .catch()=>{/"output the
error to the console /11 [21:58, 1/31/2022] Gold Port: Assume the training feature matrix X is a (p+1)*N matrix, where p is the number of predictors and N is the sample size of training data, and p>N. Assume X is of full rank, i.e. rank(X)=r=N