Learn Node Js MCQs

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

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

1) To handle file operations

2) To manage HTTP requests

3) To parse URLs

4) To create TLS/SSL secure connections

Answer : Option 4

How do you use the `readFile()` method from the `fs.promises` API?

1) To read file data synchronously

2) To create a readable stream

3) To manage file paths

4) To read file data asynchronously and return a Promise

Answer : Option 4

What does the `process.memoryUsage()` method return?

1) The total system memory

2) The system load averages

3) The memory usage of the current script

4) An object describing the memory usage of the Node.js process

Answer : Option 4

How do you use the `child_process.exec()` method?

1) To spawn a new process

2) To create a readable stream

3) To handle file operations

4) To execute a command in a shell and buffer the output

Answer : Option 4

What is the purpose of the `path.basename()` method?

1) To join multiple paths

2) To normalize a path

3) To resolve an absolute path

4) To return the last portion of a path

Answer : Option 4

How do you handle HTTP PUT requests in Express.js?

1) Using `app.post()` method

2) Using `app.get()` method

3) Using `app.delete()` method

4) Using `app.put()` method

Answer : Option 4

What does the `util.promisify()` function do?

1) Converts Promises to callbacks

2) Handles synchronous operations

3) Parses JSON data

4) Converts callback-based functions to return Promises

Answer : Option 4

How do you use the `fs.watchFile()` method?

1) To read file data asynchronously

2) To create a writable stream

3) To manage file paths

4) To watch for changes to a file and notify when it changes

Answer : Option 4

What is the role of the `os.userInfo()` method?

1) To get system load averages

2) To manage file systems

3) To parse URLs

4) To return information about the current user

Answer : Option 4

How do you handle HTTP DELETE requests in Express.js?

1) Using `app.post()` method

2) Using `app.get()` method

3) Using `app.put()` method

4) Using `app.delete()` method

Answer : Option 4