Learn Node Js MCQs

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

How do you set up error handling middleware in Express.js?

1) Using `app.use((err, req, res, next) => { ... })`

2) Using `app.error()`

3) Using `app.catch()`

4) Using `app.handleError()`

Answer : Option 1

What is the purpose of the `path.join()` method in Node.js?

1) To join multiple path segments into a single path

2) To parse a file path

3) To get the file extension

4) To read a file

Answer : Option 1

How do you use the `http` module to handle incoming HTTP requests?

1) By using `http.createServer()`

2) By using `http.request()`

3) By using `http.get()`

4) By using `http.write()`

Answer : Option 1

What does the `os.totalmem()` method return?

1) The total amount of system memory

2) The free amount of system memory

3) The used amount of system memory

4) The system memory usage percentage

Answer : Option 1

How do you use the `console` module for logging in Node.js?

1) By using methods like `console.log()`, `console.error()`, etc.

2) By using `fs` module

3) By using `debug` module

4) By using `process` module

Answer : Option 1

What is the `app.post()` method used for in Express.js?

1) To define POST routes

2) To handle middleware

3) To start the server

4) To manage sessions

Answer : Option 1

How do you create a new Express.js application?

1) Using `express()`

2) Using `app.create()`

3) Using `express.create()`

4) Using `new Express()`

Answer : Option 1

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

1) To perform an HTTP GET request

2) To create an HTTP server

3) To handle HTTP requests

4) To send HTTP responses

Answer : Option 1

How do you define custom middleware in Express.js?

1) By using `app.use()`

2) By using `app.route()`

3) By using `app.get()`

4) By using `app.post()`

Answer : Option 1

What does the `os.uptime()` method return?

1) The system uptime in seconds

2) The system load average

3) The system memory usage

4) The system CPU usage

Answer : Option 1