-
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()
-
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
-
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
-
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
-
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)
-
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()
-
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
-
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()
-
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
-
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