Nodejs Patterns

Async control flow, error handling, module design, streams, and production hardening

492 stars 68 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add cosmicstack-labs/mercury-agent-skills --skill nodejs-patterns
Manual install
git clone --depth 1 https://github.com/cosmicstack-labs/mercury-agent-skills.git /tmp/mercury-agent-skills
mkdir -p ~/.claude/skills
cp -r /tmp/mercury-agent-skills/categories/backend/nodejs-patterns ~/.claude/skills/nodejs-patterns

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Node.js Patterns

Production-grade Node.js backend patterns.

## Async Patterns

### Prefer Async/Await
```javascript
// Good
async function getUser(id) {
  const user = await db.findUser(id);
  return user;
}

// Avoid raw callbacks or.then() chains
```

### Parallel Execution
```javascript
// Sequential (slow)
const user = await fetchUser(id);
const posts = await fetchPosts(id);

// Parallel (fast)
const [user, posts] = await Promise.all([
  fetchUser(id),
  fetchPosts(id),
]);
```

## Error Handling

### Global Handler
```javascript
process.on('uncaughtException', (err) => {
  console.error('Uncaught:', err);
  // Graceful shutdown
  server.close(() => process.exit(1));
});

process.on('unhandledRejection', (reason) => {
  console.error('Unhandled Rejection:', reason);
});
```

### Express Error Middleware
```javascript
app.use((err, req, res, next) => {
  const status = err.status || 500;
  res.status(status).json({
    error: err.message,
    ...(process.env.NODE_ENV === 'development' && { stack: err.stack }),
  });
});
```

## Module Design
- Single responsibility per module
- Export a class or factory function, not plain objects
- Use dependency injection for testability
- Prefer CommonJS (require) or ESM (import), consistent throughout

## Production Hardening
- Cluster mode for multi-core
- Process manager (PM2) with auto-restart
- Health check endpoints
- Graceful shutdown (SIGTERM handler)
- Memory limit monitoring
- Structured logging (pino/winston)
Read the full skill on GitHub

Details

Skill name
nodejs-patterns
Path
categories/backend/nodejs-patterns/SKILL.md
License
MIT
Repo updated
25 August 2026

FAQ

What does the Nodejs Patterns skill do?

Async control flow, error handling, module design, streams, and production hardening

How do I install the Nodejs Patterns skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add cosmicstack-labs/mercury-agent-skills --skill nodejs-patterns. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Nodejs Patterns popular?

It lives in cosmicstack-labs/mercury-agent-skills, which has 492 GitHub stars and 68 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.