sb-dev/openquant / .agents/skills/node
node
VerifiedProvides domain-specific best practices for Node.js development with TypeScript, covering type stripping, async patterns, error handling, streams, modules, testing, performance, caching, logging, and more. Use when setting up Node.js projects with native TypeScript support, configuring type stripping (--experimental-strip-types), writing Node 22+ TypeScript without a build step, or when the user mentions 'native TypeScript in Node', 'strip types', 'Node 22 TypeScript', '.ts files without compilation', 'ts-node alternative', or needs guidance on error handling, graceful shutdown, flaky tests, profiling, or environment configuration in Node.js. Helps configure tsconfig.json for type stripping, set up package.json scripts, handle module resolution and import extensions, and apply robust patterns across the full Node.js stack.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.3 KB |
| rules/assets/graceful-server.test.ts | script | 2.6 KB |
| rules/assets/graceful-server.ts | script | 2.2 KB |
| rules/async-patterns.md | markdown | 3.1 KB |
| rules/caching.md | markdown | 4.8 KB |
| rules/environment.md | markdown | 6.0 KB |
| rules/error-handling.md | markdown | 3.8 KB |
| rules/flaky-tests.md | markdown | 10.4 KB |
| rules/graceful-shutdown.md | markdown | 4.6 KB |
| rules/logging.md | markdown | 4.4 KB |
| rules/modules.md | markdown | 2.0 KB |
| rules/node-modules-exploration.md | markdown | 3.6 KB |
| rules/performance.md | markdown | 2.8 KB |
| rules/profiling.md | markdown | 3.9 KB |
| rules/streams.md | markdown | 5.1 KB |
| rules/stuck-processes-and-tests.md | markdown | 3.9 KB |
| rules/testing.md | markdown | 4.4 KB |
| rules/typescript.md | markdown | 5.5 KB |
| tile.json | config | 1017 B |
rules/modules.md
View on GitHub---
name: modules
description: ES Modules and CommonJS patterns
metadata:
tags: modules, esm, commonjs, imports, exports
---
# Node.js Modules
## Prefer ES Modules
Use ES Modules (ESM) for new projects:
```json
// package.json
{
"type": "module"
}
```
```typescript
// Named exports (preferred)
export function processData(data: Data): Result {
// ...
}
export const CONFIG = {
timeout: 5000,
};
// Named imports
import { processData, CONFIG } from './utils.js';
```
## File Extensions in ESM
Always include file extensions in ESM imports:
```typescript
// GOOD - explicit extension
import { helper } from './helper.js';
import config from './config.json' with { type: 'json' };
// BAD - missing extension (works in bundlers but not native ESM)
import { helper } from './helper';
```
## Barrel Exports
Use index files to simplify imports:
```typescript
// src/utils/index.ts
export { formatDate, parseDate } from './date.js';
export { formatCurrency } from './currency.js';
export { validateEmail } from './validation.js';
// Consumer
import { formatDate, formatCurrency } from './utils/index.js';
```
## Default vs Named Exports
Prefer named exports for better refactoring and tree-shaking:
```typescript
// GOOD - named exports
export function createServer(config: Config): Server {
// ...
}
export function createClient(config: Config): Client {
// ...
}
// AVOID - default exports
export default function createServer(config: Config): Server {
// ...
}
```
## Dynamic Imports
Use dynamic imports for code splitting and conditional loading:
```typescript
async function loadPlugin(name: string): Promise<Plugin> {
const module = await import(`./plugins/${name}.js`);
return module.default;
}
// Conditional loading
const { default: heavy } = await import('./heavy-module.js');
```
## __dirname and __filename in ESM
Use `import.meta.dirname` and `import.meta.filename` (Node.js 20.11+):
```typescript
import { join } from 'node:path';
const configPath = join(import.meta.dirname, 'config.json');
const currentFile = import.meta.filename;
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |