N
N
ntloff2021-03-13 22:27:55
Node.js
ntloff, 2021-03-13 22:27:55

FS without repeats?

How to enter text into a file without repetition?

fs.appendFile('d:\\a\\logs.txt', `[${today}] [${displaytime}] `+message.toString()+"\n", err => {
    if (err) {
      console.error(err)
      return
    }
  })

This code adds repeated text to the file.
And I need without them. How to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-03-14
@Lynn

Create the string you want to write.
Read the file line by line comparing the lines with the created one.
If there are matches, then do nothing, otherwise write the line to the file.
Believe that in the process the neighboring process did not write anything to the file (if there are several processes)
Or, as suggested in the comments, take any database, the same sqlite.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question