express

📁 poletron/custom-rules 📅 Jan 26, 2026
4
总安装量
2
周安装量
#47774
全站排名
安装命令
npx skills add https://github.com/poletron/custom-rules --skill express

Agent 安装分布

github-copilot 2
mcpjam 1
claude-code 1
zencoder 1
crush 1
cline 1

Skill 文档

Critical Patterns

Route Organization (REQUIRED)

// ✅ ALWAYS: Separate routes by resource
// routes/users.js
const router = express.Router();

router.get('/', usersController.list);
router.get('/:id', usersController.getById);
router.post('/', validate(createUserSchema), usersController.create);
router.put('/:id', validate(updateUserSchema), usersController.update);
router.delete('/:id', usersController.delete);

module.exports = router;

Error Handling (REQUIRED)

// ✅ ALWAYS: Centralized error handler
app.use((err, req, res, next) => {
  console.error(err.stack);
  
  const status = err.status || 500;
  const message = err.message || 'Internal Server Error';
  
  res.status(status).json({
    error: { message, status }
  });
});

// ✅ Async wrapper for async route handlers
const asyncHandler = (fn) => (req, res, next) =>
  Promise.resolve(fn(req, res, next)).catch(next);

Decision Tree

Need validation?           → Use Joi or Zod middleware
Need auth?                 → Use Passport.js or JWT middleware
Need logging?              → Use Morgan middleware
Need CORS?                 → Use cors middleware
Need rate limiting?        → Use express-rate-limit

Commands

npm init -y
npm install express
npm install -D nodemon
npm run dev