BeginnerCoder

Lesson 16 — Simple router

Map paths to handlers

A web server must decide what to do for each URL path. A router is a lookup table: path → handler function. Frameworks like Express write it as app.get("/about", handler). If no path matches, the server answers 404 (not found).

const handle = (p) => (routes[p] || notFound)();

Note: this playground runs JavaScript in your browser, not in real Node, so Node-only tools (like fs or http) are not available. The exercise is a small plain-JS simulation of the Node idea.

Why it matters: routing is the first thing every web server does with a request.

Want it another way?
Task

Add an "/about" route returning "About us", so all four paths print correctly.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Node.js Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.