This quiz is completed
Node.js File System (fs) Module - Complete Quiz (60 Questions)
Section 1: Core Concepts & API Types (Questions 1-8)
What are the three main forms of file system operations provided by the node:fs module?
Parallel, Series, and Promise
Sync, Callback, and Promise
Async, Await, and Callback
Read, Write, and Execute
How do you import the promise-based APIs using ES6 Modules?
import fs from 'node:fs/promises'import * as fs from 'node:fs'import * as fs from 'node:fs/promises'require('node:fs/promises')How do you import the callback-based APIs using CommonJS?
import * as fs from 'node:fs'const fs = require('node:fs')const fs = require('node:fs/promises')require('node:fs/promises')Which API form is preferable when maximal performance (execution time and memory allocation) is required?
Promise-based APIs
Callback-based APIs
Synchronous APIs
Stream-based APIs
What happens when a synchronous operation throws an exception?
The process crashes immediately
The exception can be handled using try…catch or allowed to bubble up
The exception is automatically logged and ignored
The operation retries automatically
In callback-based APIs, what is always the first argument to the completion callback?
The result data
An exception or error (or null/undefined on success)
The file path that was used
The number of bytes processed
Which statement about the callback API is true according to the documentation?
Callbacks are executed synchronously
Callback APIs use the threadpool for off-event-loop operations
Callback APIs are slower than sync APIs
Callback APIs cannot be used with ESM
What risk should you be aware of when performing multiple concurrent modifications on the same file?
The file may become read-only
Data corruption may occur
The event loop will block
The file will be automatically deleted
Section 2: Promise API & FileHandle (Questions 9-20)
What object does fsPromises.open() return?
fs.DirFileHandlefs.StatBufferWhat happens if you don't close a FileHandle using filehandle.close()?
The Node.js process crashes immediately
Node.js tries to auto-close it and emits a process warning
The file becomes permanently locked
The operating system closes it after 5 seconds
What event is emitted when a FileHandle has been closed?
'end''finish''close''destroy'Which method forces queued I/O operations to the OS synchronized I/O completion state without flushing modified metadata?
filehandle.sync()filehandle.datasync()filehandle.flush()filehandle.commit()What type is the filehandle.fd property?
stringFileHandlenumberBufferWhich method reads the entire contents of a file using a FileHandle?
filehandle.read()filehandle.readFile()filehandle.readAll()filehandle.getContents()What does filehandle.truncate(len) do if the file was larger than len bytes?
It deletes the file
It retains only the first
len bytesIt adds null bytes to reach
lenIt throws an error
What happens if you truncate a file to a length longer than its current size?
The operation fails
The file is extended and filled with null bytes ('\0')
The file is extended with random data
The file size remains unchanged
What is returned when filehandle.read() successfully completes?
Only the number of bytes read
An object with
bytesRead and buffer propertiesOnly the buffer with data
A promise that resolves to a string
According to the docs, what is unsafe to do with filehandle.write()?
Write strings longer than 1024 bytes
Call
filehandle.write() multiple times without waiting for the promise to settleWrite binary data
Write to a file opened in read-only mode
On Linux, what happens when you use positional writes on a file opened in append mode?
The write happens at the specified position
The kernel ignores the position argument and always appends
An error is thrown
The file is automatically reopened in write mode
Which method returns a ReadableStream for reading file contents?
filehandle.createReadStream()filehandle.readableWebStream()filehandle.getStream()filehandle.toStream()Section 3: Directory Operations (Questions 21-28)
What does fsPromises.mkdir(path, { recursive: true }) do?
Creates only the final directory, throws if parents don't exist
Creates parent directories as needed
Creates a file instead of a directory
Makes the directory read-only
What does fsPromises.mkdir() fulfill with when recursive: true and directories are created?
undefinedThe first directory path created
An array of all created directories
A
FileHandle to the directoryHow many random characters does fsPromises.mkdtemp() append to the prefix?
Four
Six
Eight
Ten
What does fsPromises.opendir() return?
A
FileHandleAn
fs.Dir objectAn array of filenames
A promise that resolves to a string
What is the default bufferSize for directory entries when using fsPromises.opendir()?
16
32
64
128
When using async iteration with an fs.Dir object, when is it automatically closed?
Never, must be closed manually
After 10 seconds
After the iterator exits
When the process ends
What does fsPromises.readdir() return when withFileTypes: true is set?
An array of strings
An array of
fs.Dirent objectsA
FileHandleA
Buffer containing directory dataWhat is the default value for the recursive option in fsPromises.readdir()?
truefalseundefinednullSection 4: File Operations - Read/Write (Questions 29-36)
What does fsPromises.readFile() return if no encoding is specified?
A string
A
Buffer objectA
FileHandleA
Uint8ArrayOn macOS, Linux, and Windows, what happens when fsPromises.readFile() is called on a directory?
It returns the directory contents as a string
The promise is rejected with an error
It returns an empty buffer
It creates a new file
Which signal can be used to abort an in-progress fsPromises.readFile() operation?
CancelSignalAbortSignalTimeoutSignalStopSignalWhat is the default flag for fsPromises.writeFile() when not specified?
'r''a''w''r+'What is the default mode for fsPromises.writeFile()?
0o6660o7770o6440o755What does the flush option in fsPromises.writeFile() do when set to true?
It clears the file before writing
It uses
filehandle.sync() to flush dataIt ignores write errors
It compresses the data
What types of data can be written using fsPromises.writeFile()?
Only strings and Buffers
Strings, Buffers, TypedArrays, DataViews, AsyncIterables, and Streams
Only JSON objects
Only strings
Why is it unsafe to use fsPromises.writeFile() multiple times on the same file without waiting for the promise to settle?
The file might be locked permanently
Race conditions and data corruption can occur
The event loop will block
The file will become read-only
Section 5: File Information & Permissions (Questions 37-44)
What does fsPromises.access() test for?
File size
User permissions for a file or directory
File type
File creation time
What is the default mode for fsPromises.access()?
fs.constants.R_OKfs.constants.W_OKfs.constants.F_OKfs.constants.X_OKWhy does the documentation recommend against using fs.access() before fs.open()?
It's slower than opening directly
It introduces a race condition
It doesn't work on Windows
It requires root privileges
What does fsPromises.stat() return?
A
FileHandleAn
fs.Stats objectA
BufferA string with file metadata
When bigint: true is passed to fsPromises.stat(), what type are numeric values?
numberbigintstringfloatWhat is the default value of throwIfNoEntry in fsPromises.stat()?
falsetrueundefinednullWhich method changes the timestamps of a symbolic link itself rather than the file it points to?
fsPromises.utimes()fsPromises.lutimes()fsPromises.chmod()fsPromises.link()What does the octal value 0o765 represent in file permissions?
Owner: read/write, Group: read, Others: execute
Owner: read/write/execute, Group: read/write, Others: read/execute
Owner: read/execute, Group: write/execute, Others: read
Owner: all, Group: all, Others: none
Section 6: Copy, Move, Delete Operations (Questions 45-52)
What flag makes fsPromises.copyFile() fail if the destination already exists?
fs.constants.COPYFILE_EXCLfs.constants.COPYFILE_FICLONEfs.constants.COPYFILE_OVERWRITEfs.constants.COPYFILE_FAILWhich copy flag attempts to create a copy-on-write reflink and fails if not supported?
fs.constants.COPYFILE_FICLONEfs.constants.COPYFILE_FICLONE_FORCEfs.constants.COPYFILE_EXCLfs.constants.COPYFILE_ALLOWWhat does fsPromises.rename() do?
Copies a file to a new location
Renames or moves a file from oldPath to newPath
Deletes the old file after copying
Creates a symbolic link
What is the default value of the force option in fsPromises.rm()?
falsetrueundefinednullWhat does setting recursive: true and force: true in fsPromises.rm() achieve?
Behavior similar to
rm -rf Unix commandCreates a backup before deletion
Only deletes empty directories
Renames instead of deletes
When recursive: true is set in fsPromises.rm(), what is the default maxRetries value?
3
5
0
10
What does fsPromises.unlink() do to a symbolic link?
Deletes the target file and the link
Removes the link without affecting the target
Converts the link to a regular file
Follows the link and deletes the target only
On Windows, what happens when you call fsPromises.rmdir() on a file (not a directory)?
The file is deleted
The promise is rejected with an
ENOENT errorThe promise is rejected with an
EISDIR errorThe operation succeeds silently
Section 7: Watching & Advanced Features (Questions 53-60)
What does fsPromises.watch() return?
A
FileHandleAn
AsyncIterator yielding event objectsA
ReadableStreamA
Promise that resolves to undefinedWhat properties do the objects yielded by fsPromises.watch() contain?
type and patheventType and filenamechange and fileaction and targetWhat is the default maxQueue value for fsPromises.watch()?
1024
2048
4096
8192
Which signal can be used to stop a fsPromises.watch() watcher?
CancelSignalAbortSignalStopSignalKillSignalWhat does fsPromises.glob() return?
An array of matching paths
An
AsyncIterator yielding matching pathsA
Promise with file contentsA
FileHandle to the first matchWhen followSymlinks is enabled in fsPromises.glob(), what happens when cycles are detected?
An error is thrown
They are not traversed recursively
The process enters an infinite loop
The symlinks are ignored completely
What is the default chunkSize for filehandle.pull() operations?
64 KB
128 KB
256 KB
512 KB
Which flag must be enabled to use experimental stream iterator features like filehandle.pull()?
--experimental-streams--experimental-stream-iter--enable-fs-iterators--allow-experimental