Why a framework
Understand the idea
Express is the routing and response work you would otherwise write by hand.
The idea
The first panel is the cycle by hand. The second is the same answer through . app.get matches method and path. res.send writes the body. You did not call writeHead yourself.
What changes
| Version | Who matches the path | Who writes the body |
|---|---|---|
| Raw http.createServer | Your if statement | res.end |
| Express app.get | The route | res.send |
| Both | Still one request | Still one response |
The command
Raw Node
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Express route
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
Both bars show 200 and Hello. The Express file is shorter because the match moved into the route.
Guided challenge
Send Hello from the Express route
GET /hello currently sends Hi. Change the route so the body is Hello.
Send Hello from the Express route
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
status 200 Hello
Hints 0/2
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.