I have json file ( I create this json file using node.js) that I read in HTML using json2html library and if the json file is present / readble then it will be uploaded in our server.
I have json2html code that reads json file and prints HTML page based on content of json file. If json file is unreadable or not present, then I want node.js / javascript to stop or exit the process so nothing gets uploaded to server. How shall I stop / exit the code from processing further if json file is not available.
I do have process.exit()
in my HTML file where I read json file . It does not exit gracefully. When I do inspect elements, it errors Uncaught (in promise) ReferenceError: process is not defined
. I do have npm i process
even though process is global. I still explicitly define const process = require('process');
in my index.js file. Still I get error while opening my html file in browser. How to get past this error. Please refer below for my code from my html file
let responseContent = fetch('studentRecords.json')
.then(function(response) {
return response.json();
})
.catch(function(err) {
process.exit(1);
});