xiaohongshu
xiaohongshu
express-to-fastify-migration
Migrate Express.js REST APIs to Fastify with automated testing, performance benchmarking, and schema generation. Use when migrating Express applications to Fastify, modernizing Node.js APIs, improving API performance, or when users mention Express to Fastify migration, Fastify conversion, API mod...
Full skill instructions
You MUST complete each phase IN ORDER. Do NOT proceed to the next phase until the current phase is complete. Report your progress after each phase.
Before writing ANY code, you MUST:
You MUST save the actual API responses BEFORE making any code changes. These are required to verify output compatibility in Phase 6.
For EACH endpoint identified in 1.1, capture the response:
# Example: save responses to files for later comparison
curl -s "http://localhost:PORT/endpoint" | jq . > /tmp/express_endpoint.json
curl -s "http://localhost:PORT/endpoint?query=test" | jq . > /tmp/express_endpoint_query.json
Save responses for:
You MUST benchmark the Express server BEFORE making any code changes. This baseline is required for performance comparison in Phase 6.
npm install autocannon --save-devnpx autocannon -c 10 -d 10 http://localhost:PORT/endpoint
STOP: You MUST report your assessment findings, saved API responses, AND Express baseline metrics before proceeding to Phase 2.
Install Fastify and equivalents for EACH Express plugin identified in Phase 1.
fastify - Core framework@fastify/helmet - Security headers (REQUIRED)@fastify/rate-limit - Rate limiting (REQUIRED)compression → @fastify/compresscors → @fastify/corscookie-parser → @fastify/cookieexpress-session → @fastify/sessionbody-parser → Built-in (no plugin needed)Keep Express installed until Phase 6 (Performance Verification) is complete. This allows you to run both servers simultaneously for benchmarking comparison.
STOP: Confirm all Fastify dependencies installed before Phase 3. Express stays installed for now.
For EACH route identified in Phase 1, you MUST:
Convert syntax using these patterns:
app.get() → fastify.get()req/res → request/replyres.json(data) → return datares.status(code).json(data) → reply.code(code); return datares.header() → reply.header()Add JSON schema for validation (REQUIRED for every route):
fastify.get('/example', {
schema: {
querystring: {
type: 'object',
properties: {
query: { type: 'string' }
}
},
response: {
200: {
type: 'object',
properties: {
data: { type: 'array' }
}
}
}
}
}, async (request, reply) => {
// handler
});
fastify.addHook('onRequest', ...)preHandler optionfastify.setErrorHandler(...)Consult references/migration_patterns.md for detailed examples.
STOP: Confirm all routes migrated with schemas before Phase 4.
Update the server entry point:
const app = Fastify({ logger: true });
app.register(helmet);
app.register(rateLimit, { max: 100, timeWindow: '1 minute' });
app.setErrorHandler((error, request, reply) => {
request.log.error(error);
reply.status(error.statusCode || 500).send({ error: error.message });
});
await app.listen({ port: PORT, host: '0.0.0.0' });
STOP: Confirm server setup complete before Phase 5.
You MUST complete ALL of these checks:
npm run build - MUST succeed with no errorsnpm test - ALL tests MUST pass@fastify/helmet, @fastify/rate-limit)Do NOT report completion until ALL boxes are checked.
Compare Fastify responses against the Express responses saved in Phase 1.
For EACH endpoint, verify the output matches:
# Capture Fastify response
curl -s "http://localhost:PORT/endpoint" | jq . > /tmp/fastify_endpoint.json
# Compare against Express baseline from Phase 1
diff /tmp/express_endpoint.json /tmp/fastify_endpoint.json
You MUST verify:
If outputs differ, fix the Fastify implementation before proceeding.
npx autocannon -c 10 -d 10 http://localhost:PORT/endpoint
| Metric | Express (Phase 1) | Fastify (Phase 6) | Improvement |
|---|---|---|---|
| Req/sec | baseline | new | X% |
| Latency | baseline | new | X% |
| Throughput | baseline | new | X% |
Expected improvements:
STOP: You MUST report BOTH the output compatibility verification AND the performance comparison table before Phase 7.
After performance verification is complete:
npm uninstall express morgan compression cors cookie-parser express-session
npm uninstall @types/express @types/morgan @types/compression @types/cors
Remove any Express-specific code that was kept for benchmarking
Final verification:
npm run build - MUST succeednpm test - ALL tests MUST passDo NOT report migration complete until Express is fully removed.
Consult these files for detailed patterns:
references/migration_patterns.md - Route and middleware conversion examplesreferences/plugin_ecosystem.md - Complete Express → Fastify plugin mappingscripts/benchmark.js - Performance benchmarkingscripts/schema_generator.js - Generate JSON schemas from examplesassets/server_template.js - Production-ready Fastify boilerplatereturn, not reply.send(JSON.stringify())afterAll(() => app.close())For typed routes:
interface QueryParams {
query?: string;
}
fastify.get<{ Querystring: QueryParams }>(
'/search',
{ schema: { querystring: { type: 'object', properties: { query: { type: 'string' } } } } },
async (request, reply) => {
const { query } = request.query; // Typed!
return { results: [] };
}
);
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience