Learn Node Js MCQs

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

What is the purpose of `crypto.createCipheriv()` in Node.js?

1) To create a hash

2) To generate random bytes

3) To create a cipher for encryption

4) To sign a message

Answer : Option 3

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

1) fs.mkdirSync()

2) fs.createDir()

3) fs.mkdir()

4) fs.createDirectory()

Answer : Option 3

Which method is used to resolve a relative path into an absolute path in Node.js?

1) path.join()

2) path.relative()

3) path.resolve()

4) path.normalize()

Answer : Option 3

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

1) Reads the contents of a file asynchronously

2) Writes to a file synchronously

3) Reads the contents of a file synchronously

4) Appends to a file synchronously

Answer : Option 3

Which method is used to create an HTTP client request in Node.js?

1) http.connect()

2) http.send()

3) http.request()

4) http.fetch()

Answer : Option 3

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

1) Copies properties from one object to another

2) Formats a string

3) Inherits prototype methods from one constructor into another

4) Creates a new constructor

Answer : Option 3

Which module in Node.js provides utilities for working with streams?

1) events

2) http

3) stream

4) url

Answer : Option 3

How do you remove a file asynchronously in Node.js?

1) fs.delete()

2) fs.remove()

3) fs.unlink()

4) fs.destroy()

Answer : Option 3

Which method is used to convert a URL string into an object in Node.js?

1) url.stringify()

2) url.resolve()

3) url.parse()

4) url.decode()

Answer : Option 3

What does the `tls.connect()` method do?

1) Creates a TCP server

2) Creates a secure HTTP server

3) Initiates a secure connection

4) Closes a secure connection

Answer : Option 3