跳到正文
Skillpedia
API 与服务器(后端)41k · #6714

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/wshobson/agents/blob/main/plugins/javascript-typescript/skills/nodejs-backend-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  1. Use TypeScript: Type safety prevents runtime errors
  2. Implement proper error handling: Use custom error classes
  3. Validate input: Use libraries like Zod or Joi
  4. Use environment variables: Never hardcode secrets
  5. Implement logging: Use structured logging (Pino, Winston)
  6. Add rate limiting: Prevent abuse
  7. Use HTTPS: Always in production
  8. Implement CORS properly: Don't use * in production
  9. Use dependency injection: Easier testing and maintenance
  10. Write tests: Unit, integration, and E2E tests
  11. Handle graceful shutdown: Clean up resources
  12. Use connection pooling: For databases
  13. Implement health checks: For monitoring
  14. Use compression: Reduce response size
  15. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能