mcpbeat

Nodejs Patterns

cosmicstack-labs/nodejs-patterns

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

436 tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
365
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill nodejs-patterns

The instruction itself

9 sections, as written by the author

Node.js Patterns

Production-grade Node.js backend patterns.

Async Patterns

Prefer Async/Await

// Good
async function getUser(id) {
  const user = await db.findUser(id);
  return user;
}

// Avoid raw callbacks or.then() chains

Parallel Execution

// 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

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

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)

How to use it

Copy the folder

Take cosmicstack-labs/nodejs-patterns from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.