Create New Post

Node JS MCQs - 5

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

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

    Answer: A) express-session

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

  3. Which of the following is NOT a valid HTTP status code?

    • A) 200
    • B) 404
    • C) 5000
    • D) 302

    Answer: C) 5000

  4. What is the purpose of the res.sendFile() 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 a file as an attachment in the HTTP response
    • D) To redirect the client to a new URL

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

  5. In Express.js, what is the purpose of middleware functions?

    • A) To handle routing logic
    • B) To manipulate request and response objects
    • C) To define route handlers
    • D) To send static files to clients

    Answer: B) To manipulate request and response objects

  6. Which of the following middleware is commonly used for parsing JSON data in Express.js?

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

    Answer: A) express.json()

  7. In Express.js, which HTTP method is used to delete a resource?

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

    Answer: D) DELETE

  8. What is the purpose of the app.all() function in Express.js?

    • A) To specify middleware functions for all HTTP methods
    • B) To define route handlers for all HTTP methods
    • C) To handle all HTTP requests regardless of method
    • D) To start the Express.js application

    Answer: C) To handle all HTTP requests regardless of method

  9. Which of the following is NOT true about Express.js?

    • A) It is a lightweight web application framework for Node.js
    • B) It provides a robust set of features for building web applications and APIs
    • C) It is suitable only for front-end development
    • D) It allows for easy routing, middleware configuration, and request handling

    Answer: C) It is suitable only for front-end development

  10. What is the purpose of the app.use(express.static()) function in Express.js?

    • A) To serve static files such as HTML, CSS, and JavaScript
    • B) To handle routing logic
    • C) To authenticate users
    • D) To manipulate request and response objects

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

Comments

Leave a Reply

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

74690