app.listen() starts an HTTP server for your Express app and binds it to a TCP port (or a UNIX socket). It is identical to Node.js http.Server.listen() and returns the http.Server instance.
Call it after you register routes with app.get() and other methods. The Express hello-world app listens on port 3000 and logs when ready.
Syntax
Call app.listen in your Express.js app. Start with this line.
Required. TCP port. If omitted or 0, the OS assigns an unused port.
host
Required. Interface to bind — for example '127.0.0.1' or '0.0.0.0'.
backlog
Required. Max length of the pending connections queue (advanced).
path
Required. UNIX socket path instead of host/port (for example '/tmp/sock').
callback
Required. Called when listening (or with an error on bind failure in Express 5).
Return Value
app.listen() returns an http.Server (Node’s HTTP server). Keep that reference when you need close(), address info, or HTTPS upgrades — the return value is not app.
Express
const server = app.listen(3000, () => {
console.log('listening on', server.address());
});
// Later (tests / graceful shutdown):
// server.close();
Express.js Examples
Example 1 — Hello World Listen
Official starter pattern: route first, then listen with a ready log.
Port free → Listening on {"address":"0.0.0.0","family":"IPv4","port":8080}
Port already taken → Listen failed: listen EADDRINUSE: address already in use …
How It Works
Bind host and port.0.0.0.0 accepts connections on all IPv4 interfaces.
Check error. On failure (busy port), log and exit instead of printing a false ready message.
Success path. When error is absent, log server.address().
Why it matters. Without this check, a failed bind can look like a successful start.
Compatibility
Runtime Support
app.listen() is an Express.js application method built on Node’s HTTP server. Express 5 needs Node.js 18+. Browsers only connect to the listening host/port.
✓ Server · Express 4 & 5
app.listen()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
app.listen()Express on Node.js
Bottom line: Run examples with Node.js and the express package, then open http://localhost:<port>/ in a browser.
Frequently Asked Questions
It creates an HTTP server for your Express app and starts listening for connections on a port (or a UNIX socket). It is the same as Node’s http.Server.listen().
It runs when the server is ready. In Express 5, if listen fails (for example EADDRINUSE), the error is passed to that callback as its argument.
Use process.env.PORT with a local fallback, for example const port = process.env.PORT || 3000.
The operating system assigns an unused port. Useful for tests. Read the chosen port from server.address().
No. It starts your Node.js server. Browsers only connect to the host and port you bound.