Node.js / NestJS

Node.js Core APIs

fs, path, events, process, os, streams, buffers, child_process, worker threads

25 面接問題·
Junior
1

Which method from the fs module allows reading a file asynchronously?

回答

fs.readFile() reads the entire file asynchronously and returns its content in a callback. The fs.read() method exists but works with file descriptors for partial reads. fs.readFileSync() is the synchronous version. This asynchronous API avoids blocking the event loop during expensive I/O operations.

2

What is the main difference between path.join() and path.resolve()?

回答

path.join() simply concatenates path segments, while path.resolve() resolves paths into an absolute path from the current directory. For example, path.join('a', 'b') returns 'a/b', while path.resolve('a', 'b') returns a complete absolute path like /current/dir/a/b. Use path.resolve() to get guaranteed absolute paths.

3

Which flag to use with fs.writeFile() to append content without overwriting the file?

回答

The 'a' flag (append) opens the file in append mode, preserving existing content and adding to the end. The default 'w' flag (write) overwrites the file. Other flags exist like 'r' (read), 'wx' (write exclusive), etc. Flags are inherited from the POSIX system and provide fine control over file opening behavior.

4

Which method from the path module normalizes a path by resolving . and .. segments?

5

How to create a directory and all its missing parents with fs?

+22 面接問題

次の面接に向けてNode.js / NestJSをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める