Learn Node Js MCQs

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

What does the `http.createServer()` method do?

1) Creates an HTTPS server

2) Handles HTTP requests

3) Manages HTTP responses

4) Creates an HTTP server

Answer : Option 4

How do you access query parameters in Express.js?

1) Using `req.params`

2) Using `req.body`

3) Using `req.headers`

4) Using `req.query`

Answer : Option 4

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

1) To pause the process

2) To restart the process

3) To handle errors

4) To terminate the process with a specific exit code

Answer : Option 4

How do you perform a basic file read operation in Node.js?

1) Using `fs.read()`

2) Using `fs.createReadStream()`

3) Using `fs.open()`

4) Using `fs.readFile()`

Answer : Option 4

How do you enable debugging in Node.js?

1) By using `console.log()`

2) By using `fs` module

3) By using `process` module

4) By using the `debug` package or `--inspect` flag

Answer : Option 4

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

1) Logs object properties

2) Parses JSON data

3) Handles HTTP requests

4) Formats and returns a string representation of an object

Answer : Option 4

How do you create a readable stream in Node.js?

1) Using `fs.createWriteStream()`

2) Using `http.createServer()`

3) Using `Buffer` class

4) Using `fs.createReadStream()`

Answer : Option 4

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

1) To handle HTTP requests

2) To manage file systems

3) To work with child processes

4) To create TLS/SSL secure connections

Answer : Option 4

How do you handle incoming data in an HTTP request?

1) Using `req.data` property

2) Using `res.write()` method

3) Using `process.stdin`

4) Using `req.on("data", callback)` event

Answer : Option 4

What does the `http.get()` method do?

1) Creates an HTTP server

2) Handles HTTP responses

3) Manages file streams

4) Performs an HTTP GET request

Answer : Option 4