Question 1
In the context of the 'express.json()' middleware, what is the purpose of the 'reviver' option?
To set a limit on the size of the JSON payload.
To transform the parsed JSON object before it is made available in 'req.body'.
To revive a server that has crashed after receiving a JSON payload.
To specify the content-type that the middleware will parse.
Question 2
When using 'express.urlencoded({ extended: false })', how would the query string 'user[name]=John&user[email]=john@example.com' be parsed in 'req.body'?
{ user: [ 'John', 'john@example.com' ] }
{ user: { name: 'John', email: 'john@example.com' } }
It would throw an error because nested objects are not supported.
{ 'user[name]': 'John', 'user[email]': 'john@example.com' }
Question 3
Which of the following statements most accurately describes the primary role of middleware in a distributed system?
It provides a simplified, high-level interface for application developers to interact with the operating system's core functionalities.
It directly manages hardware resources for the operating system.
It acts as a 'software glue' that enables communication and data management for disparate applications, often across a network.
It is a type of application software that provides services directly to the end-user.
Question 4
In Morgan.js, what is the primary difference in logging behavior when the 'immediate' option is set to 'true'?
It only logs requests that result in an immediate server error.
It provides a more detailed log format.
It logs the request as soon as the headers are received, before the response is sent.
It logs the request immediately to a file instead of the console.
Question 5
What happens if you send a JSON payload with a 'Content-Type' of 'application/json' to an Express app that only uses 'express.urlencoded({ extended: true })' and not 'express.json()'?
The application will crash with a 'TypeError'.
The server will automatically parse the JSON into 'req.body'.
'req.body' will contain the raw JSON string.
'req.body' will be an empty object '{}'.
Question 6
How would you configure Morgan.js to log all requests with a status code of 400 or higher, and ignore all others?
app.use(morgan('combined', { stream: (req, res) => res.statusCode >= 400 }))
app.use(morgan('combined', { skip: (req, res) => res.statusCode < 400 }))
app.use(morgan('combined', { immediate: true, status: '>= 400' }))
app.use(morgan.skip((req, res) => res.statusCode < 400))
Question 7
Which statement correctly identifies the relationship between 'express.json()' and the 'body-parser' library?
'express.json()' and 'body-parser.json()' are competing libraries that should not be used together.
'body-parser' is now deprecated and 'express.json()' is the official replacement.
'express.json()' is essentially 'body-parser.json()' integrated directly into the Express framework.
'express.json()' is a lightweight alternative to 'body-parser' with fewer features.
Question 8
The 'express.urlencoded()' middleware uses the 'qs' library when 'extended: true'. What is a key advantage of 'qs' over the default 'querystring' library?
It can parse nested objects and arrays from the URL-encoded data.
It provides better performance for simple, flat query strings.
It allows for larger payloads to be processed.
It automatically sanitizes all input to prevent XSS attacks.
Question 9
What is the purpose of the 'inflate' option in 'express.json()' and 'express.urlencoded()'?
To increase the payload size limit by 'inflating' it.
To expand shorthand JSON into a more verbose format.
To convert a flat object into a nested object.
To automatically decompress request bodies with 'Content-Encoding' of 'gzip' or 'deflate'.
Question 10
Consider the Morgan.js custom format: 'morgan(':method :url :status :res[content-length] - :response-time ms')'. Which part of this is a custom token definition?
':method'
':response-time'
None of the above
':res[content-length]'
There are 10 questions to complete.