Create New Post

Node JS MCQs - 8

  1. Which of the following is NOT a built-in middleware function in Express.js?

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

    Answer: D) express.validate()

  2. In Express.js, what is the purpose of the res.cookie() method?

    • A) To send an HTTP response with JSON data
    • B) To set cookies in the client's browser
    • C) To send an HTTP response with HTML content
    • D) To redirect the client to a new URL

    Answer: B) To set cookies in the client's browser

  3. Which of the following is a common template engine used with Express.js for server-side rendering?

    • A) React
    • B) Angular
    • C) Vue.js
    • D) EJS

    Answer: D) EJS

  4. What does REST stand for in the context of web services?

    • A) Real-time Service Technology
    • B) Remote Execution Service Toolkit
    • C) Representational State Transfer
    • D) Responsive Service Transformation

    Answer: C) Representational State Transfer

  5. In Express.js, what does the req.originalUrl property return?

    • A) The original URL requested by the client
    • B) The current URL of the request
    • C) The base URL of the application
    • D) The query string of the URL

    Answer: A) The original URL requested by the client

  6. Which method is used to set up route-specific middleware in Express.js?

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

    Answer: C) router.use()

  7. What is the purpose of the express.Router() function in Express.js?

    • A) To define route-specific middleware
    • B) To create an instance of the Express application
    • C) To define route handlers
    • D) To initialize the Express.js server

    Answer: A) To define route-specific middleware

  8. In Express.js, how can you access route parameters?

    • A) Using req.query
    • B) Using req.body
    • C) Using req.params
    • D) Using req.headers

    Answer: C) Using req.params

  9. Which of the following middleware is commonly used for session management in Express.js?

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

    Answer: C) express-session

  10. What is the purpose of the req.baseUrl property in Express.js?

    • A) To access request query parameters
    • B) To access the base URL of the application
    • C) To access URL route parameters
    • D) To access request body parameters

    Answer: B) To access the base URL of the application

Comments

Leave a Reply

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

39995