0
I made a function that works when run from node app.js
, but when I run with Nodemon it starts and reboots forever.
The function in question is used to write a JSON to a file. I need to use Nodemon because it greatly optimizes my time.
Detail: when I use another file format, .txt
for example, it works normally, but I need the file to be in format .json
because I will store the data Baco information in it.
My job:
async function grava_login(){
fs.writeFile("data.json", JSON.stringify({name: "Mohamed Almaci"}),
"utf8", async function grava_login(err){
try{
if(err){
console.log(err);
}
else{
console.log("The file was saved!");
}
}
catch{
console.log("Erro ao salvar dados no arquivo json!")
}
})}
grava_login()
It should be "restarting forever" because your script always writes a new file in a folder that is probably watched by Listener nodemon...
– Luiz Felipe
I tried to change more didn’t work, but the strange thing is that in other file formats works :(
– user212376