Learn Node Js MCQs

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

What does `os.freemem()` return?

1) The amount of free system memory in bytes

2) The total memory of the system

3) The system's hostname

4) The system's CPU architecture

Answer : Option 1

How do you create a new directory synchronously in Node.js?

1) Using `fs.mkdirSync()`

2) Using `fs.mkdir()`

3) Using `fs.mkdirpSync()`

4) Using `fs.createDirSync()`

Answer : Option 1

Which method is used to append data to a file in Node.js?

1) fs.appendFile()

2) fs.writeFile()

3) fs.createFile()

4) fs.insertFile()

Answer : Option 1

What is the purpose of the `dns.resolve4()` method?

1) To resolve a domain name to an array of IPv4 addresses

2) To resolve an IP address to a domain name

3) To check if a domain name is available

4) To manage DNS records

Answer : Option 1

How do you handle a rejected promise in Node.js?

1) Using `.catch()` method

2) Using `.then()` method

3) Using `.finally()` method

4) Using `process.exit()`

Answer : Option 1

What is the purpose of `crypto.randomBytes()`?

1) To generate cryptographically strong pseudo-random data

2) To encrypt data using a specified algorithm

3) To decrypt data using a specified key

4) To hash data using a specified algorithm

Answer : Option 1

Which method is used to read the contents of a file synchronously in Node.js?

1) fs.readFileSync()

2) fs.readFile()

3) fs.openSync()

4) fs.createReadStream()

Answer : Option 1

How do you listen for the end event on a readable stream?

1) on('end')

2) on('data')

3) on('close')

4) on('error')

Answer : Option 1

Which method is used to create a readable stream in Node.js?

1) fs.createReadStream()

2) fs.createWriteStream()

3) fs.readFile()

4) fs.readFileSync()

Answer : Option 1

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

1) Converts a callback-based function to return a promise

2) Creates a deep clone of an object

3) Formats a string using placeholders

4) Inherits prototype methods from one constructor to another

Answer : Option 1