Learn Node Js MCQs

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

How do you use the `child_process` module in Node.js?

1) To spawn and manage child processes

2) To handle HTTP requests

3) To manage file systems

4) To parse URLs

Answer : Option 1

What is the purpose of the `fs.watch()` method?

1) To watch for changes to a file or directory

2) To read a file

3) To write to a file

4) To delete a file

Answer : Option 1

How do you handle asynchronous operations with Promises in Node.js?

1) By chaining `.then()` and `.catch()` methods

2) By using `async/await` syntax

3) By using callback functions

4) By using `setTimeout()`

Answer : Option 1

What is the purpose of the `path` module in Node.js?

1) To handle and manipulate file and directory paths

2) To handle HTTP requests

3) To manage child processes

4) To work with streams

Answer : Option 1

How do you perform input validation in a Node.js application?

1) Using libraries like `express-validator` or `joi`

2) By using regular expressions

3) By writing custom validation functions

4) All of the above

Answer : Option 4

What is the purpose of the `os.cpus()` method?

1) To return information about the system CPUs

2) To return information about the system memory

3) To return information about the operating system

4) To return information about the system architecture

Answer : Option 1

How do you create and manage multiple routes in an Express.js application?

1) Using `express.Router()`

2) Using `app.use()`

3) Using `app.route()`

4) Using `app.all()`

Answer : Option 1

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

1) Creates a readable stream for a file

2) Creates a writable stream for a file

3) Reads a file synchronously

4) Writes to a file asynchronously

Answer : Option 1

How do you handle HTTP headers in Express.js?

1) Using `res.set()` or `res.header()`

2) Using `req.headers`

3) Using `app.use()`

4) Using `res.send()`

Answer : Option 1

What is the purpose of the `http.createServer()` method?

1) To create an HTTP server

2) To handle HTTP requests

3) To manage file systems

4) To create a readable stream

Answer : Option 1