When using the fs module to write to files, sometimes you’re going to write to a JSON file.

const contentStream = fs.createWriteStream(

            "./src/utilities/corpus/corpora/" + fileName + ".txt",

            {flags: "a"}

        );

or

 fs.writeFile(
    "./src/utilities/corpus/corpora/" + fileName + "-master.json"
    , JSON.stringify(masterList)
    , (err) => { 
        if (err) { throw err; }
        console.log("Data written to file");
    }); 

I’ve found that this can cause what seems like node to crash out and stop, you will more likely to hit this during development because whats actually happening is nodemon is seeing the new .json file and breaking out of the session.

To solve this issue, In your acakage.json or however you are calling nodemon you can use the snippet ” –ignore src/**/*.json “

So your script will look like

 "scripts": {"debug": "nodemon --inspect-brk=9229 ./dist/index.js --ignore src/**/*.json"}, 

This means that nodemon will ignore the newly created .json files created by the fs.writeFile().