-1

user_bw = message.content;
fs.writeFile("badwordlog.txt", user_bw, (err) => {
  if (err)
    console.log(err);
  else {
    console.log("badwordlog edited !");
       
  }
});

I need to store all the badwords in a file . How to print the next word in the next line? I tried \n but it was not working.

Jane
  • 1
  • 1
  • 1
    Hi ! On which server platform ? Unix-like, Windows ? In the second case, you could try with `\r\n` ? – Philippe Sep 30 '21 at 12:41

1 Answers1

2

The reason for this is that writeFile will replace the whole file. You can pass in a option flag which tells it to append new text to it. You may try:

user_bw = message.content;
fs.writeFile("badwordlog.txt", user_bw, { flag: "a+" }, (err) => {
  if (err)
    console.log(err);
  else {
    console.log("badwordlog edited !");
       
  }
});