Create New Post

Node JS MCQs - 9

  1. Which of the following Express.js methods is used to handle HTTP OPTIONS requests?

    • A) app.options()
    • B) app.get()
    • C) app.post()
    • D) app.delete()

    Answer: A) app.options()

  2. What is the purpose of the express.static() middleware in Express.js?

    • A) To serve static files such as HTML, CSS, and JavaScript
    • B) To handle authentication
    • C) To manage session data
    • D) To handle routing logic

    Answer: A) To serve static files such as HTML, CSS, and JavaScript

  3. Which of the following is a common task performed by middleware in Express.js?

    • A) Defining routes
    • B) Authenticating users
    • C) Rendering views
    • D) Parsing JSON data

    Answer: D) Parsing JSON data

  4. What is the purpose of the res.clearCookie() method in Express.js?

    • A) To send an HTTP response with JSON data
    • B) To set cookies in the client's browser
    • C) To delete a cookie from the client's browser
    • D) To send a file as an attachment in the HTTP response

    Answer: C) To delete a cookie from the client's browser

  5. In Express.js, what is the purpose of the req.protocol property?

    • A) To access the request method
    • B) To access the request headers
    • C) To access the request URL
    • D) To access the request protocol (HTTP or HTTPS)

    Answer: D) To access the request protocol (HTTP or HTTPS)

  6. Which of the following Express.js methods is used to handle HTTP HEAD requests?

    • A) app.head()
    • B) app.get()
    • C) app.post()
    • D) app.delete()

    Answer: A) app.head()

  7. What is the purpose of middleware chaining in Express.js?

    • A) To execute middleware in a specific order
    • B) To combine multiple middleware functions into one
    • C) To handle routing logic
    • D) To manage session data

    Answer: A) To execute middleware in a specific order

  8. Which of the following Express.js methods is used to define middleware that is only executed for a specific HTTP method and route?

    • A) app.use()
    • B) app.route()
    • C) router.use()
    • D) router.route()

    Answer: B) app.route()

  9. What is the purpose of the res.setHeader() method in Express.js?

    • A) To set the HTTP status code of the response
    • B) To set response headers
    • C) To send an HTTP response with JSON data
    • D) To send an HTTP response with HTML content

    Answer: B) To set response headers

  10. In Express.js, what does the req.route property contain?

    • A) The request method
    • B) The request headers
    • C) The route parameters
    • D) The route object

    Answer: D) The route object

Comments

Leave a Reply

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

70075