Carefully study the given code that is calling the loadJSON method and answer the question that follows.
loadJSON("new.json", function (err, data)
{ if(err)console.log("Error in file reading", err.message);
else
console.log(data);
});
Which of the following is the correct function definition of the loadJSON method such that if a file named "neW.json" is present in the project, then its data is displayed, otherwise error message (error in file reading) is displayed?
Correct Answer: var file1 = require('fs'); function loadJSON(file_name, arg){ file1.readFile(file_name, function(error1, data){ if(error1)return arg(error1); try{ var new_parse =JSON.parse(data); } catch(error1) { return arg(error1); } return arg(null, new_parse); }); }
Explanation:
Note: This Question is unanswered, help us to find answer for this one
More Node.js MCQ Questions