Recall & Review
beginner
What Node.js module is commonly used to check if a file exists and to get file stats?
The
fs (File System) module is used to check file existence and retrieve file stats in Node.js.Click to reveal answer
beginner
How does
fs.stat() help when working with files?fs.stat() returns information about a file, such as size, creation date, and whether it is a file or directory.Click to reveal answer
intermediate
What is the difference between
fs.existsSync() and fs.access()?fs.existsSync() synchronously checks if a file exists, while fs.access() asynchronously checks file accessibility and permissions.Click to reveal answer
intermediate
Why is
fs.exists() deprecated and what should you use instead?fs.exists() is deprecated because it can lead to race conditions. Instead, use fs.access() or try to open the file directly.Click to reveal answer
beginner
What does
stats.isFile() return when called on a file stats object?It returns
true if the path is a regular file, otherwise false.Click to reveal answer
Which method would you use to synchronously check if a file exists in Node.js?
✗ Incorrect
fs.existsSync() is the synchronous method to check file existence.What does
fs.stat() provide about a file?✗ Incorrect
fs.stat() returns metadata such as size, creation time, and type.Which method is recommended instead of the deprecated
fs.exists()?✗ Incorrect
fs.access() is recommended to check file accessibility safely.What does
stats.isDirectory() return if the path is a folder?✗ Incorrect
stats.isDirectory() returns true if the path is a directory.Which Node.js module must you import to use
fs.stat()?✗ Incorrect
The
fs module provides file system methods like stat().Explain how to check if a file exists asynchronously in Node.js and how to get its size.
Think about using fs.access first, then fs.stat for details.
You got /4 concepts.
Describe why using fs.exists() is discouraged and what safer alternatives exist.
Focus on safety and modern Node.js practices.
You got /4 concepts.