The if/else chain checking req.url in the http-server lesson works, but it doesn't scale — a real site has dozens of routes, needs to read data out of the URL, and has to handle several HTTP methods per route. Express is a package, installed with npm, that handles all of this for you.
npm install expressCompare this to the raw http version from earlier in the course:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('Welcome home')
})
app.get('/about', (req, res) => {
res.send('About this site')
})
app.listen(3000, () => {
console.log('Server running at http://localhost:3000')
})No manual req.url checking, no manually calling writeHead() and end() — app.get(path, handler) registers a route directly, and res.send() figures out the right Content-Type on its own.
Underneath, Express is still built on the same http module from earlier in this course — it isn't a replacement for what you've learned, it's a much friendlier layer on top of it. Everything about req and res you already know still applies; Express just adds convenience methods like res.send() and res.json() around them.
app.use((req, res) => {
res.status(404).send('Not found')
})Placed after every other route, this catches any request that didn't match one of them above it — Express checks routes in the order they're defined, top to bottom.
Express isn't part of Node.js itself — it's the single most widely used third-party package for building servers in Node, but it's a normal npm dependency like any other, not something built in.
The next few lessons build this out properly: multiple routes, middleware, and reading data the browser sends along with a request.