0
0
Expressframework~10 mins

Middleware composition for auth layers in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a middleware that logs every request.

Express
app.use([1]);
Drag options to blanks, or click blank then click option'
AloggerMiddleware
Bexpress.json()
Ccors()
DbodyParser.urlencoded()
Attempts:
3 left
💡 Hint
Common Mistakes
Using middleware that parses JSON instead of logging.
Forgetting to pass a function to app.use.
2fill in blank
medium

Complete the code to protect a route with authentication middleware.

Express
app.get('/dashboard', [1], (req, res) => { res.send('Welcome!'); });
Drag options to blanks, or click blank then click option'
AloggerMiddleware
Bcors()
CauthMiddleware
Dexpress.static('public')
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated middleware like logger or cors for authentication.
Placing middleware after the route handler.
3fill in blank
hard

Fix the error in composing two middleware functions for a route.

Express
app.post('/submit', [1], (req, res) => { res.send('Submitted'); });
Drag options to blanks, or click blank then click option'
AauthMiddleware || loggerMiddleware
BauthMiddleware, loggerMiddleware
CauthMiddleware && loggerMiddleware
D[authMiddleware, loggerMiddleware]
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical operators instead of array or separate arguments.
Passing middleware as a comma-separated string.
4fill in blank
hard

Fill both blanks to create a middleware chain that first authenticates, then logs the request.

Express
app.use([1], [2]);
Drag options to blanks, or click blank then click option'
AauthMiddleware
BloggerMiddleware
Cexpress.json()
Dcors()
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of middleware.
Using unrelated middleware like cors or json parser.
5fill in blank
hard

Fill all three blanks to create a route with JSON parsing, authentication, and logging middleware.

Express
app.post('/api/data', [1], [2], [3], (req, res) => { res.json({ success: true }); });
Drag options to blanks, or click blank then click option'
Aexpress.json()
BauthMiddleware
CloggerMiddleware
Dcors()
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong order of middleware causing errors.
Using cors middleware instead of logger.