回答編集履歴

1

ヘルプに明記されていたので引用

2019/02/28 00:42

投稿

maisumakun
maisumakun

スコア145184

test CHANGED
@@ -1,4 +1,8 @@
1
1
  [こちら](https://blog.kubosho.com/entry/why-deprecated-of-fs-exists/)にありますように、`fs.exists`には**競合状態**(存在チェックの直後にファイルの作成・削除などが行われると想定どおりに進まない)問題があります。
2
+
3
+
4
+
5
+ > Using fs.exists() to check for the existence of a file before calling fs.open(), fs.readFile() or fs.writeFile() is not recommended. Doing so introduces a race condition, since other processes may change the file's state between the two calls. Instead, user code should open/read/write the file directly and handle the error raised if the file does not exist. ([Node.jsドキュメント](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback)より)
2
6
 
3
7
 
4
8