plugins/aai-stack-node/skills/node-performance/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-stack-node/skills/node-performance/SKILL.md -a claude-code --skill node-performanceInstallation paths:
.claude/skills/node-performance/# Node.js Performance Skill
Patterns for optimizing Node.js application performance.
## Memory Management
### Heap Snapshots
```typescript
import v8 from 'v8'
import fs from 'fs'
// Take heap snapshot
function takeHeapSnapshot(filename: string): void {
const snapshotStream = v8.writeHeapSnapshot(filename)
console.log(`Heap snapshot written to ${snapshotStream}`)
}
// Expose via endpoint
app.get('/debug/heap', (req, res) => {
const filename = `/tmp/heap-${Date.now()}.heapsnapshot`
takeHeapSnapshot(filename)
res.download(filename)
})
// Memory usage
function getMemoryUsage(): object {
const usage = process.memoryUsage()
return {
heapUsed: Math.round(usage.heapUsed / 1024 / 1024) + 'MB',
heapTotal: Math.round(usage.heapTotal / 1024 / 1024) + 'MB',
external: Math.round(usage.external / 1024 / 1024) + 'MB',
rss: Math.round(usage.rss / 1024 / 1024) + 'MB',
}
}
```
### Avoiding Memory Leaks
```typescript
// BAD: Growing array
const cache: any[] = []
function addToCache(item: any) {
cache.push(item) // Never cleared
}
// GOOD: LRU cache with limit
import { LRUCache } from 'lru-cache'
const cache = new LRUCache<string, any>({
max: 500, // Max items
maxSize: 50 * 1024 * 1024, // 50MB
sizeCalculation: (value) => JSON.stringify(value).length,
ttl: 1000 * 60 * 5, // 5 minutes
})
// BAD: Event listener leak
class Service {
constructor(emitter: EventEmitter) {
emitter.on('data', this.handleData.bind(this))
// Never removed
}
}
// GOOD: Cleanup listeners
class Service {
private handler: (data: any) => void
constructor(private emitter: EventEmitter) {
this.handler = this.handleData.bind(this)
emitter.on('data', this.handler)
}
destroy() {
this.emitter.off('data', this.handler)
}
}
```
## CPU Optimization
### Worker Threads
```typescript
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads'
import os from 'os'
if (isMainThread) {
// Main thread