Express vs Fastify: Let Me Show You the Difference
I’ve used both Express.js and Fastify in real projects.
At first, they feel almost the same.
You create a server. Add routes. Return responses.
But once you go a bit deeper, the differences start showing up.
So instead of just talking, let me walk you through it like I actually tested it.
Step 1: Basic Server
Express
import express from "express";
const app = express();
app.get("/", (req, res) => {
res.send({ message: "Hello from Express" });
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});Simple. No friction.
Fastify
import Fastify from "fastify";
const app = Fastify();
app.get("/", async (request, reply) => {
return { message: "Hello from Fastify" };
});
app.listen({ port: 3000 });Also simple. Slightly different style, but nothing crazy.
At this point, both feel the same.
Step 2: Add Validation
Now things start getting interesting.
Express
You need an external library like zod or joi.
app.post("/user", (req, res) => {
// manually validate
const { name } = req.body;
if (!name) {
return res.status(400).send({ error: "Name is required" });
}
res.send({ name });
});You handle validation yourself.
Fastify
Validation is built-in.
app.post(
"/user",
{
schema: {
body: {
type: "object",
required: ["name"],
properties: {
name: { type: "string" },
},
},
},
},
async (request) => {
return request.body;
}
);Fastify validates automatically before hitting your handler.
This is where I started noticing:
Fastify forces structure.
Express lets you decide everything.
Step 3: Performance Feel
I didn’t run benchmarks at first.
But when I pushed both under load:
Express handled it fine
Fastify felt lighter and faster
That’s because Fastify is designed with performance in mind from the start.
You don’t “optimize later.”
You start optimized.
Step 4: Project Growth
This is where the real difference hit me.
In Express
After a few routes:
Different files had different patterns
Middleware usage was inconsistent
Validation logic was scattered
It still worked.
But it started getting messy.
In Fastify
Because of:
Plugins
Schemas
Structure
Everything stayed consistent.
It felt like the framework was guiding me:
“Do it this way. It’ll scale better.”
Step 5: TypeScript Experience
This one surprised me.
With Express:
I had to manually type a lot
Request/response types felt loose
With Fastify:
Types were inferred nicely
Less guesswork
Fewer mistakes
If you’re using TypeScript seriously, this matters a lot.
So What Did I Realize?
It’s not about which one is “better.”
It’s about how you like to work.
Express feels like:
Do whatever you want.
Fastify feels like:
Do it properly from the start.
When I Personally Use Each
I reach for Express when:
I need something quick
It’s a small project
I don’t want structure overhead
I pick Fastify when:
The project will grow
Performance matters
I want consistency across the codebase
Final Thought
At the start, Express feels easier.
But over time, Fastify starts making more sense.
Not because it’s flashy.
But because it removes a lot of small problems before they even happen.