Learn Node Js MCQs

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

How do you create a buffer from an array of bytes in Node.js?

1) Buffer.alloc()

2) Buffer.fromArray()

3) Buffer.from()

4) Buffer.concat()

Answer : Option 3

Which module in Node.js is used to perform DNS lookups and name resolution functions?

1) net

2) http

3) dns

4) url

Answer : Option 3

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

1) Start a new process

2) Pause the current process

3) Exit the Node.js process

4) Restart the process

Answer : Option 3

How do you handle errors in asynchronous code in Node.js?

1) Using throw statements

2) Using try/catch

3) Using callbacks or Promises

4) Using return statements

Answer : Option 3

Which module in Node.js provides an API for interacting with the operating system?

1) fs

2) path

3) os

4) events

Answer : Option 3

What does the `fs.existsSync()` method do?

1) Read a file synchronously

2) Create a file synchronously

3) Check if a file exists synchronously

4) Delete a file synchronously

Answer : Option 3

Which method is used to listen for incoming data on a readable stream in Node.js?

1) stream.listen()

2) stream.receive()

3) stream.on('data')

4) stream.read()

Answer : Option 3

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

1) The number of CPUs

2) The CPU usage

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

4) The CPU architecture

Answer : Option 3

How do you write to a file synchronously in Node.js?

1) fs.appendFileSync()

2) fs.readFileSync()

3) fs.writeFileSync()

4) fs.insertFileSync()

Answer : Option 3

Which object in Node.js is used to handle binary data directly?

1) BufferData

2) ArrayBuffer

3) Buffer

4) Uint8Array

Answer : Option 3