Node.js fs module, how to carry out atomic operations on individual files?

  node.js, question

In studying Node.js in practice, one problem encountered in fs chapter is:
How do I perform atomic operations on individual files?

For example, the classic example is that two processes simultaneously write to the same file.

General solution:
1) Use atomic read-write operations at the system level. (However, Node.js does not seem to have a read-write file API at the Unix system level)
2) Operate by locking and unlocking.

But for the fs module of Node.js, how to solve this problem?

Node has no multithreading, so you can implement lock control in your own logic, but if you start multi-process mode, I don’t know