Master Node.js core concepts including event loop, modules, npm, and asynchronous programming patterns
Teaches Node.js fundamentals including event loop, modules, npm, and async patterns.
/plugin marketplace add pluginagentmarketplace/custom-plugin-nodejs/plugin install nodejs-developer-plugin@pluginagentmarketplace-nodejssonnetYour expert guide to mastering the core concepts of Node.js runtime, from understanding the event loop to managing packages with npm. This agent helps you build a solid foundation in Node.js backend development.
// Understanding event loop phases
console.log('Start');
setTimeout(() => {
console.log('Timeout');
}, 0);
Promise.resolve().then(() => {
console.log('Promise');
});
console.log('End');
// Output: Start → End → Promise → Timeout
// CommonJS
const express = require('express');
module.exports = { myFunction };
// ES Modules
import express from 'express';
export { myFunction };
export default app;
npm init -y # Initialize project
npm install express # Install dependency
npm install -D jest # Install dev dependency
npm update # Update packages
npm audit fix # Fix security issues
npm run build # Run custom script
npm publish # Publish package
// 1. Callbacks (old way)
fs.readFile('file.txt', (err, data) => {
if (err) throw err;
console.log(data);
});
// 2. Promises (better)
fs.promises.readFile('file.txt')
.then(data => console.log(data))
.catch(err => console.error(err));
// 3. Async/Await (modern)
async function readFile() {
try {
const data = await fs.promises.readFile('file.txt');
console.log(data);
} catch (err) {
console.error(err);
}
}
Ask the Node.js Fundamentals Agent when you:
// ❌ Bad: Blocking operation
const result = heavyComputation(); // Blocks all other operations
// ✅ Good: Non-blocking
setImmediate(() => {
const result = heavyComputation();
});
// ❌ Bad: Silent failure
async function fetchData() {
return await fetch(url); // Unhandled if it fails
}
// ✅ Good: Proper error handling
async function fetchData() {
try {
return await fetch(url);
} catch (error) {
console.error('Fetch failed:', error);
throw error; // Re-throw or handle
}
}
// ❌ Bad: Memory leak
emitter.on('event', handler); // Handler never removed
// ✅ Good: Clean up
emitter.once('event', handler); // Auto-removes
// OR
emitter.removeListener('event', handler); // Manual cleanup
^1.2.3 - Compatible (>=1.2.3 <2.0.0)~1.2.3 - Approximately (>=1.2.3 <1.3.0)1.2.3 - Exact version* - Latest version| Problem | Root Cause | Solution |
|---|---|---|
| Event loop blocking | Synchronous CPU-intensive operation | Use worker_threads or setImmediate |
| Memory leak | Unremoved event listeners | Use once() or manual removeListener() |
| Module not found | Incorrect path or missing dependency | Check node_modules, run npm install |
| Unhandled promise rejection | Missing .catch() or try/catch | Add global handler + local catches |
| ECONNRESET | Connection closed unexpectedly | Implement retry with backoff |
□ Check Node.js version: node --version (use LTS)
□ Verify dependencies: npm ls --depth=0
□ Check for circular dependencies: madge --circular .
□ Monitor event loop lag: require('perf_hooks')
□ Profile memory: node --inspect + Chrome DevTools
□ Check for blocking operations: clinic doctor
□ Verify async error handling: process.on('unhandledRejection')
// Enable debug logging
DEBUG=* node app.js
// Common error patterns:
// "ENOENT" → File/directory not found
// "EACCES" → Permission denied
// "EADDRINUSE" → Port already in use
// "ETIMEDOUT" → Connection timeout
// "ERR_MODULE_NOT_FOUND" → ESM import failed
Event Loop Freeze
// Detect with blocked-at package
const blocked = require('blocked-at');
blocked((time, stack) => {
console.log(`Blocked for ${time}ms at:`, stack);
});
Memory Exhaustion
# Increase heap size
node --max-old-space-size=4096 app.js
# Generate heap snapshot
node --inspect app.js
# Then: Chrome DevTools → Memory → Take Snapshot
Graceful Shutdown
process.on('SIGTERM', async () => {
console.log('Graceful shutdown initiated');
await server.close();
await mongoose.disconnect();
process.exit(0);
});
Use this agent to verify that a Python Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a Python Agent SDK app has been created or modified.
Use this agent to verify that a TypeScript Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a TypeScript Agent SDK app has been created or modified.