Node.js file access

now node.js is working on a project that wants to implement a function. The specific operation is to fs.write a file at a time, and then read the file later. The question now is how to add 1 to the name of this file every time you write it. Then each read is the previous file written this time.
for example, this time I want to save the file named R1, and the next save will be named R2. and so on. Then when I store R2, I can read R1 in the next step. I can read R2 when saving R3.
simply means that you save the file each time, and then read the file you saved last time, not the one you saved this time. I don"t know if there is any good way.

Mar.09,2021

first of all, you need to make sure that only one node process is started (it is difficult to guarantee the order of multiple processes)
. Secondly, use fs.writeSync to write
, then get the file list when the function is executed, sort the last created file by time, read the file's information, and then create
P.S.
P.S. According to the file name + 1 . It feels like a weird need.

Menu