New to Rust? Grab our free Rust for Beginners eBook Get it free →
Node.js Connect and Express: Exploring Use Cases and Applications

If you’re starting a web server in Node.js, you’ll come across both Connect and Express, and it isn’t obvious how they relate. Both are frameworks that pass each request through middleware, small functions that run in order, while Express also maps each URL and method to the code that handles it.
I’ll run the same middleware in both frameworks to show where Express’s routing changes your code.
What Node.js, Connect, and Express mean
Node.js provides the JavaScript runtime and built-in HTTP APIs. Connect adds an ordered middleware stack, while Express adds routing and middleware.
Connect is a separate middleware framework for Node.js HTTP servers.
Both Connect and Express use middleware, but Express 4 removed its dependency on Connect. Think of them as two frameworks that share a request-handling style, not as a stack where Connect sits underneath Express.
| Technology | What it provides | Where it fits |
|---|---|---|
| Node.js | Runtime and built-in HTTP server API | Foundation for a server |
| Connect | Ordered middleware stack | Standalone HTTP middleware framework |
| Express | Routing plus middleware | Web apps and APIs |
The practical distinction is routing. Connect’s app receives a request through its middleware stack, while Express also matches a method and path to a route handler.
How middleware moves a request
Middleware is a function that runs while a request is being handled, with access to request, response, and next in Express.
app.use((req, res, next) => {
res.setHeader('X-Request-Stage', 'middleware-ran');
next();
});
Order matters because each function either ends the response or hands control onward. A function that does neither leaves the request waiting.
Express handles routes and middleware
The example uses the Express and Connect packages installed in a Node.js project. Save the code as article-sample.js in that project, then run node article-sample.js.
I ran the Express and Connect handlers against local HTTP requests. Each returned status 200, the middleware header, and its own response body.

const express = require('express');
const connect = require('connect');
const http = require('node:http');
const app = express();
app.use((req, res, next) => {
res.setHeader('X-Request-Stage', 'middleware-ran');
next();
});
app.get('/hello', (req, res) => res.send('Hello from Express'));
const server = app.listen(0, () => {
http.get(`http://127.0.0.1:${server.address().port}/hello`, res => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
console.log('Express:', res.statusCode, res.headers['x-request-stage'], body);
server.close();
runConnect();
});
});
});
function runConnect() {
const app = connect();
app.use((req, res, next) => {
res.setHeader('X-Request-Stage', 'middleware-ran');
next();
});
app.use((req, res) => res.end('Hello from Connect'));
const server = http.createServer(app).listen(0, () => {
http.get(`http://127.0.0.1:${server.address().port}/hello`, res => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
console.log('Connect:', res.statusCode, res.headers['x-request-stage'], body);
server.close();
});
});
});
}
The client request starts after the server is listening, and server.close() frees its socket when the response ends.
Connect exposes a middleware stack
Connect’s app is a request-listener function that you can pass to node:http’s createServer(). Each app.use() call adds a middleware function to the stack.
| Question | Connect | Express |
|---|---|---|
| How does a request enter? | Through the middleware stack | Through the app’s middleware and routing layers |
| How does it choose a route? | Middleware can inspect the request or mount path | Route methods match HTTP method and path |
| Does Express depend on Connect? | Not applicable | No, Express 4 removed that dependency |
Choose Express when your app needs its routing API. Adding Connect underneath Express is not a prerequisite.
When a middleware leaves a request hanging
Every middleware path must either send a response or pass control onward. If a conditional branch returns without calling next() or ending the response, the client keeps waiting.
- Use next() when another middleware or route should handle the request.
- Send or end the response when the current handler has the final result.
Error-handling middleware follows a separate Express signature with four arguments, (err, req, res, next). Keep it after the middleware and routes whose errors it should handle.
Choose the abstraction that matches the job
Use Node.js HTTP when you want to build the request handling yourself, Connect when an ordered middleware stack is the task, and Express when route matching belongs in the framework. Express and Connect are separate choices, even though their middleware functions use a similar handoff model.
node package/server.js
What is Connect in Node.js?
Connect is a Node.js middleware framework that composes request handlers into an ordered stack.
Does Express use Connect?
Express 4 removed its dependency on Connect. Express has its own routing and middleware framework.
What does middleware next() do?
Calling next() passes control to the next middleware or matching handler. A middleware must also end the response when it has the final result.




