Challenge - 5 Problems
Express Server Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when accessing the root URL?
Consider this Express server code. What will the server respond with when you visit
http://localhost:3000/ in a browser?Express
import express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('Hello from Express!'); }); app.listen(3000);
Attempts:
2 left
💡 Hint
Look at the route defined with
app.get and what it sends back.✗ Incorrect
The server listens on port 3000 and responds to GET requests at '/' with the text 'Hello from Express!'. So visiting the root URL shows that text.
📝 Syntax
intermediate2:00remaining
Which option correctly creates an Express server listening on port 8080?
Choose the code snippet that correctly starts an Express server on port 8080.
Attempts:
2 left
💡 Hint
Remember to call express as a function and use the correct method to start the server.
✗ Incorrect
Option A correctly calls express() to create the app and uses app.listen with a callback to confirm the server is running.
🔧 Debug
advanced2:00remaining
Why does this Express server code crash?
This code crashes when run. What is the cause of the error?
Express
import express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('Welcome!'); }); app.listen();
Attempts:
2 left
💡 Hint
Check the app.listen() method usage.
✗ Incorrect
app.listen() requires a port number to know where to listen. Omitting it causes a runtime error.
❓ state_output
advanced2:00remaining
What is the response when accessing '/user/42'?
Given this Express route, what will the server respond with when visiting
/user/42?Express
import express from 'express'; const app = express(); app.get('/user/:id', (req, res) => { res.send(`User ID is ${req.params.id}`); }); app.listen(3000);
Attempts:
2 left
💡 Hint
Look at how route parameters are accessed in Express.
✗ Incorrect
The route uses a parameter :id, which is accessed via req.params.id. So the response includes the actual value '42'.
🧠 Conceptual
expert2:00remaining
What happens if you call app.listen() twice in the same Express app?
Consider an Express app where
app.listen(3000) is called, and later app.listen(4000) is called again. What is the expected behavior?Attempts:
2 left
💡 Hint
Think about how Node.js servers handle multiple listen calls on the same app instance.
✗ Incorrect
Calling app.listen() twice on the same Express app instance causes an error because the underlying HTTP server is already running.