Node.js / NestJS

Node.js Core APIs

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

25 câu hỏi phỏng vấn·
Junior
1

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

Câu trả lời

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()?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Node.js / NestJS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí