Learn Node Js MCQs

Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.

What is the role of the `events` module in Node.js?

1) To manage file operations

2) To create HTTP servers

3) To parse URLs

4) To handle asynchronous events and event emitters

Answer : Option 4

How do you use `fs.createReadStream()`?

1) To write data to a file

2) To create a writable stream

3) To manage file paths

4) To read data from a file in a stream

Answer : Option 4

What is the purpose of the `process.nextTick()` method?

1) To handle asynchronous code

2) To create a readable stream

3) To manage file systems

4) To schedule a callback to be invoked on the next iteration of the event loop

Answer : Option 4

How do you handle child processes in Node.js?

1) By using `http` module

2) By using `fs` module

3) By using `events` module

4) By using the `child_process` module

Answer : Option 4

What does the `path.join()` method do?

1) Extracts the file extension

2) Normalizes a path

3) Parses a URL

4) Joins multiple path segments into a single path

Answer : Option 4

How do you use `async/await` in Node.js?

1) To manage file systems

2) To create HTTP servers

3) To parse URLs

4) To handle asynchronous operations with a more readable syntax

Answer : Option 4

What does the `os.cpus()` method return?

1) The total system memory

2) The system load averages

3) The hostname of the machine

4) An array of objects containing information about each CPU/core

Answer : Option 4

How do you use the `path.resolve()` method?

1) To parse a URL

2) To normalize a path

3) To join multiple paths

4) To resolve a sequence of paths or path segments into an absolute path

Answer : Option 4

What is the `module.exports` object used for?

1) To create new modules

2) To handle asynchronous code

3) To manage file operations

4) To export functions or objects from a module

Answer : Option 4

How do you use the `fs.promises` API?

1) To perform synchronous file system operations

2) To manage file paths

3) To handle HTTP requests

4) To perform promise-based file system operations

Answer : Option 4