Challenge - 5 Problems
Express Flow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when next() is called in Express middleware?
Consider this Express middleware function:
What will be printed to the console when a request is made?
app.use((req, res, next) => {
console.log('Middleware 1');
next();
console.log('After next');
});What will be printed to the console when a request is made?
Express
app.use((req, res, next) => {
console.log('Middleware 1');
next();
console.log('After next');
});Attempts:
2 left
💡 Hint
Think about what next() does and when the code after it runs.
✗ Incorrect
Calling next() passes control to the next middleware but does not stop the current function. So, 'Middleware 1' is logged, then next() moves to the next middleware, but after next() call, 'After next' is also logged.
❓ lifecycle
intermediate2:00remaining
How does next() affect error handling middleware?
Given these middleware functions:
What will the client receive when a request is made?
app.use((req, res, next) => {
next('error');
});
app.use((err, req, res, next) => {
res.send('Error handled');
});What will the client receive when a request is made?
Express
app.use((req, res, next) => {
next('error');
});
app.use((err, req, res, next) => {
res.send('Error handled');
});Attempts:
2 left
💡 Hint
What happens when next() is called with a string argument?
✗ Incorrect
Calling next() with an argument triggers Express to skip normal middleware and jump to error-handling middleware. So the error handler sends 'Error handled' to the client.
📝 Syntax
advanced2:00remaining
Which middleware setup causes a runtime error?
Identify which option will cause an error when a request is made:
Attempts:
2 left
💡 Hint
Check if calling next() after sending a response causes issues.
✗ Incorrect
Calling next() after res.send() can cause Express to try to send another response, leading to a runtime error about headers already sent.
🔧 Debug
advanced2:00remaining
Why does this middleware never call next() or send a response?
Look at this middleware:
What happens if req.query.pass is false or missing?
app.use((req, res, next) => {
if (req.query.pass) {
next();
}
});What happens if req.query.pass is false or missing?
Express
app.use((req, res, next) => {
if (req.query.pass) {
next();
}
});Attempts:
2 left
💡 Hint
What happens if middleware neither calls next() nor sends a response?
✗ Incorrect
If next() is not called and no response is sent, Express waits indefinitely, causing the request to hang.
🧠 Conceptual
expert3:00remaining
What is the effect of calling next('route') in Express middleware?
Consider this route setup:
What response will the client receive when requesting '/test'?
app.get('/test', (req, res, next) => {
next('route');
}, (req, res) => {
res.send('First handler');
});
app.get('/test', (req, res) => {
res.send('Second handler');
});What response will the client receive when requesting '/test'?
Express
app.get('/test', (req, res, next) => { next('route'); }, (req, res) => { res.send('First handler'); }); app.get('/test', (req, res) => { res.send('Second handler'); });
Attempts:
2 left
💡 Hint
What does next('route') do inside route middleware?
✗ Incorrect
Calling next('route') skips the remaining middleware for the current route and moves to the next matching route handler. So the second handler responds.