用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill node-backend-dev命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | node-backend-dev |
| description | > Use when this capability is needed. |
Build production-ready Node.js backend APIs with Express, Hono, or ElysiaJS. Includes routing, middleware, validation, database access, error handling, auth, WebSocket, and testing patterns.
Request: $ARGUMENTS
| Framework | Best For | Runtime | Validation |
|---|---|---|---|
| Express | Mature ecosystem, middleware depth | Node.js | Manual (Zod) |
| Hono | Edge/lightweight, multi-runtime | Node/Bun/Deno/Edge | @hono/zod-validator |
| ElysiaJS | Bun-native, type-safe DI | Bun | TypeBox (built-in) |
| Fastify | Plugin ecosystem, schema-first | Node.js | JSON Schema (built-in) |
# Node.js (Express or Hono)
mkdir my-api && cd my-api
npm init -y
npm install typescript tsx @types/node --save-dev
npx tsc --init --strict --module nodenext --moduleResolution nodenext --outDir dist
# Bun (ElysiaJS)
bun init
bun add elysia
src/
index.ts # Entry point
routes/
v1/ # Versioned routes
users.ts
health.ts
middleware/
auth.ts
error-handler.ts
cors.ts
rate-limit.ts
services/ # Business logic layer
user.service.ts
db/
index.ts # DB client singleton
schema/ # ORM schema definitions
migrations/ # Migration files
config/
env.ts # Environment validation at startup
types/
index.ts # Shared type definitions
Read: references/framework-setup.md for entry point examples per framework and environment validation with Zod.
Read: references/routing-examples.md for complete route definitions per framework (Express, Hono, ElysiaJS).
routes/v1/./api/v1/. When v2 is needed, create routes/v2/ and mount separately.GET /api/health (outside versioned prefix).Read: references/middleware-examples.md for auth, CORS, security headers, logging, and rate limiting examples per framework.
Read: references/validation-examples.md for Zod schema definitions and validation patterns per framework (Express, Hono, ElysiaJS).
Read: references/database-setup.md for ORM setup (Prisma, Drizzle, raw pg), connection pooling, and service layer pattern.
Read: references/error-handling-examples.md for AppError class, PostgreSQL error mapping, and global error handlers per framework.
Read: references/auth-patterns.md for session-based (Better Auth), token-based (JWT), dev bypass, and optional auth middleware.
Extended examples with all three frameworks:
references/websocket.md
.ws() with built-in Bun WebSocket. Supports subscribe/publish for topic-based pub/sub.ws library with WebSocketServer attached to the HTTP server.@hono/node-ws with createNodeWebSocket() and upgradeWebSocket() helper.type WsMessage =
| { type: 'join'; payload: { roomId: string } }
| { type: 'leave'; payload: { roomId: string } }
| { type: 'message'; payload: { roomId: string; content: string } }
| { type: 'typing'; payload: { roomId: string; isTyping: boolean } };
Hold a server reference so services can publish events without importing WebSocket internals.
class Broadcaster {
private wss: WebSocketServer | null = null;
attach(wss: WebSocketServer) { this.wss = wss; }
publish(topic: string, data: unknown) {
if (!this.wss) return;
const message = JSON.stringify({ topic, data });
this.wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) client.send(message);
});
}
}
export const broadcaster = new Broadcaster();
Read: references/testing-examples.md for framework-specific test invocation, validation tests, service mocking, and DB cleanup.
| Problem | Cause | Fix |
|---|---|---|
| CORS errors in browser | Missing or misconfigured CORS middleware | Mount CORS middleware before routes. Verify allowed origins include the frontend URL with protocol. |
| Connection pool exhaustion | Too many PrismaClient instances or unclosed connections | Use singleton pattern (Step 5). Set max pool size to 10-20. Close pools on SIGTERM. |
| Middleware not executing | Middleware mounted after the route it should protect | Mount middleware before routes. Express processes middleware in registration order. |
| Async error crashes process | Unhandled promise rejection in route handler | Express: wrap handlers with try/catch and call next(err), or use express-async-errors. Hono/Elysia: errors in async handlers are caught automatically. |
| Port already in use (EADDRINUSE) | Previous process still bound to the port | Kill the old process: lsof -ti :3000 | xargs kill (Unix) or npx kill-port 3000. |
| ECONNREFUSED to database | Database not running or wrong connection string | Verify DATABASE_URL, confirm the database is accepting connections, check firewall rules. |
| Request body undefined | Missing JSON body parser middleware | Express: add app.use(express.json()) before routes. Hono/Elysia: built-in, no extra step needed. |
| TypeBox validation errors cryptic | Default ElysiaJS error format lacks field-level detail | Use .onError() hook to reformat validation errors into the standard { error: { code, message, details } } shape. |
| Drizzle migrations out of sync | Schema changed without generating migration | Run npx drizzle-kit generate after schema changes, then npx drizzle-kit migrate. |
| JWT token rejected after deploy | Different JWT_SECRET between environments | Validate JWT_SECRET in env.ts at startup. Use the same secret across all instances in an environment. |
{ error: { code, message, details? } }) across all endpointsGET /api/health that verifies DB connectivitycreateMiddleware() from hono/factory when extracting Hono middleware to separate files (preserves type safety)express.json() after route definitions -- body parsing must happen before handlers executeSource: abhayla/claude-best-practices — distributed by TomeVault.