Create New Post

Node JS MCQs - 4

  1. Which of the following modules is commonly used for routing in Node.js web applications?

    • A) http
    • B) fs
    • C) express
    • D) os

    Answer: C) express

  2. What is the purpose of the res.send() method in Express.js?

    • A) To send an HTTP response with JSON data
    • B) To send an HTTP response with HTML content
    • C) To send an HTTP response with a file attachment
    • D) To send an HTTP request to another server

    Answer: B) To send an HTTP response with HTML content

  3. In the context of Express.js middleware, what does next() do?

    • A) Moves to the next route handler
    • B) Ends the current request-response cycle
    • C) Sends the response to the client
    • D) Starts a new request-response cycle

    Answer: A) Moves to the next route handler

  4. 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

  5. Which of the following is a valid way to create a route handler in Express.js?

    • A) app.route('/users').get(handlerFunction)
    • B) app.get('/users', handlerFunction)
    • C) Both A and B
    • D) None of the above

    Answer: C) Both A and B

  6. What does the app.use() function do in Express.js?

    • A) Declares a new route handler
    • B) Specifies middleware functions to be executed for every request
    • C) Sets up a static file server
    • D) Starts the Express.js application

    Answer: B) Specifies middleware functions to be executed for every request

  7. What is the purpose of the req.query 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: A) To access request query parameters

  8. Which of the following HTTP methods is used to update an existing resource in a RESTful API?

    • A) GET
    • B) POST
    • C) PUT
    • D) DELETE

    Answer: C) PUT

  9. In Express.js, what is the purpose of the res.json() method?

    • A) To send an HTTP response with JSON data
    • B) To redirect the client to a new URL
    • C) To send an HTTP response with HTML content
    • D) To render a view template

    Answer: A) To send an HTTP response with JSON data

  10. What is the purpose of the app.listen() function in Express.js?

    • A) To start the Express.js application
    • B) To create a new route handler
    • C) To specify middleware functions
    • D) To set up a static file server

    Answer: A) To start the Express.js application

Comments

Leave a Reply

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

20323