Node.js · Junior · Question 54 of 75

How do you check whether a file exists before reading it?

Explanation

Checking first creates a race condition: the file can be deleted between the check and the read. Handling the error is simpler and correct. fs.exists is deprecated.

Further reading

Problem with a question

Node.js · Junior · question 54

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz