nodejs-backend-patterns
它能做什么
这份指南帮助你使用 Node.js 搭建网络服务(后端)。它讲解如何组织代码、处理错误、保障访问安全,以及连接数据库。
适用场景
- ✓正在搭建需要服务器的网站或应用时。
- ✓正在开发供其他程序调用的 API 时。
- ✓正在构建需要实时通信的系统时。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/javascript-typescript/skills/nodejs-backend-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何为我的网上商店搭建一个安全的 Node.js 服务器?”
每周 5 个新技能,1 分钟读完。
工作原理
文中讲解了代码组织模式和最佳实践,包括如何处理传入的请求、可能出现的错误,以及如何确保只有经过授权的用户才能访问特定部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Node.js Backend Patterns
Comprehensive guidance for building scalable, maintainable, and production-ready Node.js backend applications with modern frameworks, architectural patterns, and best practices.
When to Use This Skill
- Building REST APIs or GraphQL servers
- Creating microservices with Node.js
- Implementing authentication and authorization
- Designing scalable backend architectures
- Setting up middleware and error handling
- Integrating databases (SQL and NoSQL)
- Building real-time applications with WebSockets
- Implementing background job processing
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Use TypeScript: Type safety prevents runtime errors
- Implement proper error handling: Use custom error classes
- Validate input: Use libraries like Zod or Joi
- Use environment variables: Never hardcode secrets
- Implement logging: Use structured logging (Pino, Winston)
- Add rate limiting: Prevent abuse
- Use HTTPS: Always in production
- Implement CORS properly: Don't use
*in production - Use dependency injection: Easier testing and maintenance
- Write tests: Unit, integration, and E2E tests
- Handle graceful shutdown: Clean up resources
- Use connection pooling: For databases
- Implement health checks: For monitoring
- Use compression: Reduce response size
- Monitor performance: Use APM tools
Testing Patterns
See javascript-testing-patterns skill for comprehensive testing guidance.
常见问题
什么是“中间件”?
中间件就像“守卫”或“处理器”,在请求到达主要功能之前,对其进行检查或修改。
为什么要使用 TypeScript?
TypeScript 会在程序运行前检查数据类型,帮助避免常见错误,让代码更可靠。
什么是“最佳实践”?
这是人们公认的最佳做法,能让代码更安全、更易懂,也更便于将来维护。
详情
作者的原始描述
Build production-ready Node.js backend services with Express/Fastify, implementing middleware patterns, error handling, authentication, database integration, and API design best practices. Use when creating Node.js servers, REST APIs, GraphQL backends, or microservices architectures.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6714
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …