0
0
Node.jsframework~5 mins

Checking file existence and stats in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Afs.existsSync()
Bfs.stat()
Cfs.readFile()
Dfs.access()
What does fs.stat() provide about a file?
AFile metadata like size and creation time
BFile content
CFile permissions only
DFile encoding
Which method is recommended instead of the deprecated fs.exists()?
Afs.writeFile()
Bfs.readFile()
Cfs.open()
Dfs.access()
What does stats.isDirectory() return if the path is a folder?
Afalse
Btrue
Cnull
Dundefined
Which Node.js module must you import to use fs.stat()?
Ahttp
Bpath
Cfs
Dos
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.