0
0
Expressframework~10 mins

Log levels and when to use them 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 log an informational message using Express's logger.

Express
app.use((req, res, next) => { console.[1]('Request received'); next(); });
Drag options to blanks, or click blank then click option'
Aerror
Binfo
Cwarn
Ddebug
Attempts:
3 left
💡 Hint
Common Mistakes
Using error or warn for normal request logs.
2fill in blank
medium

Complete the code to log a warning when a deprecated API endpoint is accessed.

Express
app.get('/old-endpoint', (req, res) => { console.[1]('Deprecated endpoint used'); res.send('Deprecated'); });
Drag options to blanks, or click blank then click option'
Awarn
Bdebug
Cinfo
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using info or error instead of warn for deprecation notices.
3fill in blank
hard

Fix the error in the code to log an error message when a server error occurs.

Express
app.use((err, req, res, next) => { console.[1]('Server error:', err); res.status(500).send('Error'); });
Drag options to blanks, or click blank then click option'
Awarn
Bdebug
Cinfo
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using warn or info for actual errors.
4fill in blank
hard

Fill both blanks to log detailed debugging information only when debugging is enabled.

Express
if (process.env.DEBUG) { console.[1]('Debug info:', [2]); }
Drag options to blanks, or click blank then click option'
Adebug
Berror
Creq
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using info or error for debug logs.
Logging wrong variables.
5fill in blank
hard

Fill all three blanks to create a middleware that logs errors and warns about slow responses.

Express
app.use((req, res, next) => { const start = Date.now(); res.on('finish', () => { const duration = Date.now() - [1]; if (duration > [2]) { console.[3](`Slow response: ${duration}ms`); } }); next(); });
Drag options to blanks, or click blank then click option'
Astart
B1000
Cwarn
Dres
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Logging slow responses as errors or info.