nodejs-script
Skill12 starsChanged 7 days agoMITView on GitHub
Always use this skill when writing, editing, or reviewing any Node.js script in this project.
- Reads credentials
In this repository28 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adlc-scriptingSkill
- architect-assistantSkill
- big-prod-e2e-testSkill
- ceSkill
- changelogSkill
- check-fix-buildSkill
- db-state-updateSkill
- git-branchingSkill
- github-issuesSkill
- hook-debuggingSkill
- migrations-data-integritySkill
- morning-checkSkill
- pocSkill
- post-impl-check-client-component-sizeSkill
- post-impl-check-cost-calc-no-autoSkill
- post-impl-check-indexesSkill
- post-impl-check-kb-actualSkill
- post-impl-check-migrationsSkill
- post-impl-check-performance-no-autoSkill
- post-impl-check-security-no-autoSkill
- security-checkSkill
- server-e2e-testsSkill
- session-kb-suggestSkill
- sql-reviewSkill
- ui-componentsSkill
- update-install-instructionsSkill
- use-playwrightSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 10
Use CommonJS. Never use ESM (import/export).
- Very specific: line 28
Use only Node.js built-ins: fs, path, crypto, child_process, os, util.
- Very specific: line 29
If a utility is needed (e.g.
- Distinctive: line 56
Prefer explicit exits over falling off the end of the script.
- Distinctive: line 60
Write diagnostics to stderr, not stdout (stdout may be parsed by the harness):
- Very specific: line 66
Use console.error() only if you're sure the harness ignores stderr.
- Very specific: line 70
Always use path.join() / path.resolve().
- Very specific: line 79
Use execFileSync with an array of args, never execSync with a shell string (avoids injection):
- Distinctive: line 105
Do not silently swallow errors inside helper functions — let them propagate to the top-level catch.
- Distinctive: line 109
Always ensure the output directory exists before writing:
- Very specific: line 118
Read from process.env or parse a .env file inline.
- Distinctive: line 148
Run lint and fix before finishing:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Review or write the Node.js script using these conventions:
Module System
Use CommonJS. Never use ESM (import/export).
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');Sync over Async
This is a CLI hook — keep everything synchronous. Do not use async/await, Promises, or callbacks.
- File I/O:
fs.readFileSync,fs.writeFileSync,fs.mkdirSync - Subprocesses:
execFileSyncorspawnSync(neverexec,execFile,spawn) - stdin:
fs.readFileSync('/dev/stdin', 'utf8')orprocess.stdin.fd
No External Dependencies
Use only Node.js built-ins: fs, path, crypto, child_process, os, util.
If a utility is needed (e.g. .env parsing, arg parsing), write a small inline function.
Code Style (matches ESLint config)
- Single quotes for strings
- Semicolons required
constby default;letonly when reassigned; nevervar- Strict equality:
===/!== - 2-space indentation
stdin Handling (for Claude Code hooks)
Hook scripts receive event data via stdin as JSON:
const raw = fs.readFileSync(process.stdin.fd, 'utf8');
const event = JSON.parse(raw);Wrap in try/catch — stdin may be empty or malformed.
Exit Codes
process.exit(0)— successprocess.exit(1)— unrecoverable errorprocess.exit(2)— block the action (for PreToolUse hooks that want to prevent tool execution)
Prefer explicit exits over falling off the end of the script.
Logging
Write diagnostics to stderr, not stdout (stdout may be parsed by the harness):
process.stderr.write('Error: ...\n');Use console.error() only if you're sure the harness ignores stderr.
Path Handling
Always use path.join() / path.resolve(). Never concatenate paths with string +.
const dir = path.resolve(__dirname, '../telemetry');
const file = path.join(dir, `${Date.now()}.json`);Subprocess Calls
Use execFileSync with an array of args, never execSync with a shell string (avoids injection):
const out = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
encoding: 'utf8',
timeout: 2000,
}).trim();Wrap in try/catch — the command may not exist or may fail.
Error Handling
Top-level scripts should have a single try/catch guard:
try {
const raw = fs.readFileSync(process.stdin.fd, 'utf8');
// ... main logic ...
process.exit(0);
} catch (err) {
process.stderr.write(`telemetry-hook error: ${err.message}\n`);
process.exit(1);
}Do not silently swallow errors inside helper functions — let them propagate to the top-level catch.
File Writing
Always ensure the output directory exists before writing:
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');Environment Variables
Read from process.env or parse a .env file inline. Never use dotenv package.
Simple inline .env parser:
function loadEnv(envPath) {
try {
const vars = {};
for (const line of fs.readFileSync(envPath, 'utf8').split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const eq = trimmed.indexOf('=');
if (eq === -1) continue;
const key = trimmed.slice(0, eq).trim();
let val = trimmed.slice(eq + 1).trim();
if ((val.startsWith('"') && val.endsWith('"')) ||
(val.startsWith("'") && val.endsWith("'"))) {
val = val.slice(1, -1);
}
vars[key] = val;
}
return vars;
} catch {
return {};
}
}After Changes
Run lint and fix before finishing:
npm run lint:fix
npm run lintDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

