一键导入
node
This skill should be used when the user asks to 'create a CLI tool', 'handle file system operations', 'manage processes', or 'configure runtime behavior'. Guides Node.js 20.x patterns and native APIs.
菜单
This skill should be used when the user asks to 'create a CLI tool', 'handle file system operations', 'manage processes', or 'configure runtime behavior'. Guides Node.js 20.x patterns and native APIs.
This skill should be used when the user asks to 'create an agent', 'add tool calling', 'build workflows', or 'orchestrate AI tasks'. Guides agentic AI patterns and multi-step reasoning.
This skill should be used when the user asks to 'integrate an API', 'handle streaming responses', 'add authentication', or 'manage API calls'. Covers Claude API integration and streaming patterns.
This skill should be used when the user asks to 'add a command', 'parse arguments', 'improve CLI output', or 'add interactive features'. Covers command routing, argument parsing, and stdio handling.
This skill should be used when the user asks to 'scan directories', 'read files', 'parse JSON or Markdown', or 'traverse the file system'. Guides safe file I/O patterns and recursive directory operations.
This skill should be used when the user asks to 'generate Markdown', 'create documentation', 'structure content', or 'format skill definitions'. Covers Markdown generation and structured documentation patterns.
This skill should be used when the user asks to 'add types', 'fix type errors', 'create interfaces', 'improve type safety', or 'configure TypeScript'. Provides TypeScript strict mode patterns and ESM configuration for Node.js projects.
| name | node |
| description | This skill should be used when the user asks to 'create a CLI tool', 'handle file system operations', 'manage processes', or 'configure runtime behavior'. Guides Node.js 20.x patterns and native APIs. |
| version | 1.0.0 |
| metadata | {"internal":false} |
Node.js 20.x patterns for building CLI tools with native ESM, file system operations, and process management.
.js extension imports, ESM-only packagesfs/promises, recursive traversalprocess.env"type": "module" in package.json)#!/usr/bin/env node
import { generateClaudeMd } from "./generators/claude-md.js";
const args = process.argv.slice(2);
const command = args[0];
const verbose = args.includes("--verbose");
if (command === "agents") {
const result = await generateClaudeMd();
console.log(result);
} else {
console.error(`Unknown command: ${command}`);
process.exit(1);
}
Use when: Building simple CLIs without framework dependencies. For complex argument parsing, consider commander or yargs.
import { readdir, readFile, stat } from "fs/promises";
import { join } from "path";
export async function scanDirectory(dirPath: string): Promise<string[]> {
const entries = await readdir(dirPath, { withFileTypes: true });
const files: string[] = [];
for (const entry of entries) {
const fullPath = join(dirPath, entry.name);
if (entry.isDirectory() && !shouldIgnore(entry.name)) {
const nested = await scanDirectory(fullPath);
files.push(...nested);
} else if (entry.isFile()) {
files.push(fullPath);
}
}
return files;
}
function shouldIgnore(name: string): boolean {
return name.startsWith(".") || name === "node_modules" || name === "dist";
}
Use when: Recursively traversing directories. Always use fs/promises for async operations, never synchronous fs methods in CLI tools.
import { readFile } from "fs/promises";
export async function readFileContent(filePath: string): Promise<string> {
try {
return await readFile(filePath, "utf-8");
} catch (error) {
console.error(`Failed to read ${filePath}:`, error);
return "";
}
}
Use when: Reading files that may not exist or have permission issues. Handle errors locally rather than crashing.
const API_KEY = process.env.ANTHROPIC_API_KEY;
if (!API_KEY) {
console.error("Error: ANTHROPIC_API_KEY environment variable not set");
process.exit(1);
}
Use when: Requiring configuration at runtime. Validate environment variables early in the entry point, not deep in modules.
// Always include .js extension (even for .ts source files)
import { callClaude } from "../utils/claude.js";
import { scanDirectory } from "../utils/file-system.js";
// TypeScript will resolve these correctly when transpiled
Use when: Using native ESM in Node.js 20.x. The .js extension is mandatory for ESM imports, even though source files are .ts.
import { spawn } from "child_process";
// Pass through stdout/stderr in real-time
const child = spawn("some-command", ["args"], {
stdio: "inherit", // Use parent's stdin/stdout/stderr
});
child.on("exit", (code) => {
process.exit(code ?? 0);
});
Use when: Running subprocesses where you want immediate output visibility (like --verbose mode).
try {
await runGenerator();
process.exit(0); // Success
} catch (error) {
console.error("Generation failed:", error);
process.exit(1); // Failure
}
Use when: Building CLI tools that integrate with shell scripts or CI/CD pipelines. Always exit with non-zero codes on errors.
stdio: 'inherit' for long-running operationsreadFileSync blocks the event loop - use fs/promises insteadjoin() and resolve() from path for cross-platform compatibilityrequire() CommonJS modules)