Loading

Quipoin Menu

Learn • Practice • Grow

express-js / Custom Middleware
mcq
Direction: Choose the correct option

Q1.

How do you create a custom middleware function that logs each request?
A. app.log((req) => console.log(req))
B. app.use((req, res, next) => { console.log('Request'); next(); })
C. app.middleware(logger)
D. app.use(logger())
Direction: Choose the correct option

Q2.

What is the role of the body-parser middleware (now part of Express)?
A. To enable CORS
B. To parse incoming request bodies
C. To parse cookies
D. To compress responses
Direction: Choose the correct option

Q3.

Why would you use the cors middleware in an Express app?
A. To enable Cross-Origin Resource Sharing
B. To handle errors
C. To compress responses
D. To log requests
Direction: Choose the correct option

Q4.

How do you include third-party middleware like morgan for logging?
A. require('morgan') and app.get(morgan)
B. npm install morgan then app.use(morgan('tiny'))
C. Both A and B
D. npm install morgan then app.use(morgan)
Direction: Choose the correct option

Q5.

What does the following custom middleware do? app.use((req, res, next) => { req.requestTime = Date.now(); next(); })
A. Sends a response
B. Adds a requestTime property to the request object
C. Ends the request
D. Logs the request time