Learn Node Js MCQs

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

Which module helps you manage HTTP headers in Node.js?

1) http

2) headers

3) response

4) url

Answer : Option 1

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

1) To work with streaming data

2) To manage file systems

3) To handle HTTP requests

4) To parse URLs

Answer : Option 1

How do you handle promise rejections in Node.js?

1) Using `.catch()` method

2) Using `try/catch` blocks

3) Using `process.on('unhandledRejection', callback)`

4) All of the above

Answer : Option 4

What is the purpose of the `express.Router()` function?

1) To create modular route handlers

2) To handle HTTP requests

3) To manage middleware

4) To parse request bodies

Answer : Option 1

How do you generate random numbers in Node.js?

1) Using `Math.random()`

2) Using `crypto` module

3) Using `random` module

4) Using `uuid` module

Answer : Option 1

What does the `fs.promises` API provide?

1) Promise-based file system operations

2) Callback-based file system operations

3) Synchronous file system operations

4) Stream-based file system operations

Answer : Option 1

How do you manage application secrets in Node.js?

1) Using environment variables or secret management tools

2) Using configuration files

3) Using database

4) Using hardcoded values

Answer : Option 1

What does `process.env.NODE_ENV` typically represent?

1) The environment in which the application is running (e.g., development, production)

2) The path of the current file

3) The process ID

4) The server port number

Answer : Option 1

How do you perform a bulk insert in Node.js?

1) Using database-specific methods

2) Using `fs` module

3) Using `http` module

4) Using `process` module

Answer : Option 1

What is the `cluster` module used for in Node.js?

1) To create child processes to handle load

2) To manage HTTP requests

3) To handle file uploads

4) To work with streams

Answer : Option 1