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, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно