Create New Post

Node JS MCQs - 6

  1. In Express.js, what is the purpose of the res.redirect() method?

    • A) To send an HTTP response with JSON data
    • B) To send an HTTP response with HTML content
    • C) To redirect the client to a new URL
    • D) To send a file as an attachment in the HTTP response

    Answer: C) To redirect the client to a new URL

  2. Which of the following Express.js middleware is used for parsing URL-encoded data?

    • A) express.json()
    • B) express.urlencoded()
    • C) express.static()
    • D) express.session()

    Answer: B) express.urlencoded()

  3. What is the purpose of the req.params object in Express.js?

    • A) To access request query parameters
    • B) To access request headers
    • C) To access URL route parameters
    • D) To access request body parameters

    Answer: C) To access URL route parameters

  4. Which of the following methods is used to handle errors in Express.js middleware?

    • A) app.error()
    • B) app.useError()
    • C) app.use()
    • D) app.handleError()

    Answer: C) app.use()

  5. In Express.js, what is the purpose of the res.sendStatus() method?

    • A) To send an HTTP response with a status code
    • B) To send an HTTP response with JSON data
    • C) To send an HTTP response with HTML content
    • D) To send a file as an attachment in the HTTP response

    Answer: A) To send an HTTP response with a status code

  6. What is middleware in Express.js?

    • A) A function that defines routes in Express.js
    • B) A function that handles HTTP requests and responses
    • C) A function that runs before the route handler and has access to the request and response objects
    • D) A function that sets up database connections

    Answer: C) A function that runs before the route handler and has access to the request and response objects

  7. Which of the following Express.js methods is used to define route parameters?

    • A) app.param()
    • B) app.route()
    • C) app.get()
    • D) app.use()

    Answer: A) app.param()

  8. What is the purpose of the next() function in Express.js middleware?

    • A) To end the request-response cycle
    • B) To move to the next route handler
    • C) To send the response to the client
    • D) To start a new request-response cycle

    Answer: B) To move to the next route handler

  9. What is the purpose of the res.locals object in Express.js?

    • A) To store request-specific information
    • B) To access request headers
    • C) To render view templates with local variables
    • D) To manipulate request and response objects

    Answer: C) To render view templates with local variables

  10. Which of the following Express.js methods is used to handle errors?

    • A) app.use()
    • B) app.error()
    • C) app.handleError()
    • D) app.useError()

    Answer: A) app.use()

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

66704