{"id":49604673,"url":"https://github.com/stackvault/eslint-config-node","last_synced_at":"2026-05-04T11:37:51.366Z","repository":{"id":313584709,"uuid":"1051606664","full_name":"stackvault/eslint-config-node","owner":"stackvault","description":"Node.js ESLint configuration with TypeScript","archived":false,"fork":false,"pushed_at":"2025-09-06T12:24:46.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-23T00:11:28.522Z","etag":null,"topics":["api","backend","eslint","eslint-config","eslint-plugin-n","eslint-plugin-security","eslint9","eslintconfig","flat-config","node","nodejs","security","server","stackvault","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@stackvault/eslint-config-node","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackvault.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-06T10:55:27.000Z","updated_at":"2025-09-06T12:30:42.000Z","dependencies_parsed_at":"2025-09-07T05:38:40.526Z","dependency_job_id":"d6ded960-a6c8-4756-b682-b9f192d3be8a","html_url":"https://github.com/stackvault/eslint-config-node","commit_stats":null,"previous_names":["stackvault/eslint-config-node"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stackvault/eslint-config-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackvault%2Feslint-config-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackvault%2Feslint-config-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackvault%2Feslint-config-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackvault%2Feslint-config-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackvault","download_url":"https://codeload.github.com/stackvault/eslint-config-node/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackvault%2Feslint-config-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32606339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backend","eslint","eslint-config","eslint-plugin-n","eslint-plugin-security","eslint9","eslintconfig","flat-config","node","nodejs","security","server","stackvault","typescript"],"created_at":"2026-05-04T11:37:47.640Z","updated_at":"2026-05-04T11:37:51.354Z","avatar_url":"https://github.com/stackvault.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @stackvault/eslint-config-node\n\nProduction-ready Node.js ESLint configuration with TypeScript, security rules, and performance optimizations. Built on top of [@stackvault/eslint-config-typescript](https://www.npmjs.com/package/@stackvault/eslint-config-typescript) with Node.js-specific enhancements for backend development.\n\n## Features\n\n- 🛡️ **Security First** - Built-in security scanning with eslint-plugin-security\n- 🚀 **Node.js 20+ Optimized** - Leverages modern Node.js APIs and patterns\n- 📦 **TypeScript Foundation** - Inherits all strict type checking from base config\n- ⚡ **Performance Rules** - Enforces async patterns and non-blocking operations\n- 🔒 **Promise Safety** - Comprehensive promise and async/await validation\n- 🎯 **Modern Patterns** - Prefers native Node.js APIs and ES2021+ features\n\n## Installation\n\n```bash\nnpm install --save-dev @stackvault/eslint-config-node eslint typescript\n```\n\nor with Yarn:\n\n```bash\nyarn add --dev @stackvault/eslint-config-node eslint typescript\n```\n\n## Requirements\n\n- Node.js \u003e=20.0.0 (LTS)\n- ESLint \u003e=9.22.0\n- TypeScript \u003e=5.5.0\n\n## Usage\n\nCreate an `eslint.config.js` file in your project root:\n\n```javascript\nimport nodeConfig from '@stackvault/eslint-config-node';\n\nexport default [\n  ...nodeConfig,\n  // Your custom rules here\n];\n```\n\n### With Custom Rules\n\n```javascript\nimport nodeConfig from '@stackvault/eslint-config-node';\n\nexport default [\n  ...nodeConfig,\n  {\n    rules: {\n      // Override for your specific needs\n      'n/no-process-env': 'off', // If you need direct process.env access\n      'security/detect-object-injection': 'off', // If too many false positives\n    }\n  }\n];\n```\n\n### For Microservices\n\n```javascript\nimport nodeConfig from '@stackvault/eslint-config-node';\n\nexport default [\n  ...nodeConfig,\n  {\n    rules: {\n      'n/no-process-exit': 'off', // Allow process.exit for containers\n      'n/no-sync': 'off', // Allow sync operations at startup\n    }\n  }\n];\n```\n\n## What's Included\n\n### Inherited from TypeScript Config\n\nThis configuration extends [@stackvault/eslint-config-typescript](https://www.npmjs.com/package/@stackvault/eslint-config-typescript), providing:\n\n- **Strict type checking** with type-aware rules\n- **Built-in formatting** via @stylistic/eslint-plugin (no Prettier needed)\n- **Import sorting** and organization\n- **Consistent code patterns** and naming conventions\n\n### Security Rules\n\nComprehensive security scanning to prevent common vulnerabilities:\n\n- **Path traversal protection** - Detects non-literal fs operations\n- **Command injection prevention** - Flags dangerous child_process usage\n- **RegExp DoS protection** - Identifies unsafe regular expressions\n- **Timing attack warnings** - Alerts on potential timing vulnerabilities\n- **Buffer safety** - Ensures secure buffer operations\n\n### Node.js Best Practices\n\nModern Node.js patterns enforced via eslint-plugin-n:\n\n- **Node: protocol imports** - Requires `node:fs` instead of `fs`\n- **Promise-based APIs** - Prefers `fs.promises` over callbacks\n- **Version compatibility** - Ensures Node.js 20+ API usage\n- **Global preferences** - Enforces global Buffer, process, console\n- **No blocking operations** - Prevents synchronous I/O in async contexts\n\n### Promise \u0026 Async Handling\n\nEnhanced async operation rules via eslint-plugin-promise:\n\n- **Proper error handling** - Enforces catch or return for promises\n- **Async/await patterns** - Prefers modern async over callbacks\n- **Promise chain safety** - Prevents common promise anti-patterns\n- **No floating promises** - Ensures all promises are handled\n\n### Modern JavaScript Patterns\n\nSelected Unicorn rules for cleaner code:\n\n- **Modern APIs** - `.at()`, `.replaceAll()`, structured clone\n- **Top-level await** - For ES modules\n- **Prefer for...of** - Over forEach for better performance\n- **Optional catch binding** - Cleaner error handling\n- **Native fetch** - Uses Node.js built-in fetch\n\n## Key Rules Explained\n\n### Security Patterns\n```typescript\n// ❌ Error: detect-non-literal-fs-filename\nconst file = userInput;\nfs.readFile(file, callback);\n\n// ✅ Correct: Validate and sanitize paths\nimport path from 'node:path';\nconst safePath = path.join(SAFE_DIR, path.basename(userInput));\nfs.readFile(safePath, callback);\n```\n\n### Node.js Protocol Imports\n```typescript\n// ❌ Error: prefer-node-protocol\nimport fs from 'fs';\nimport { readFile } from 'fs/promises';\n\n// ✅ Correct: Use node: protocol\nimport fs from 'node:fs';\nimport { readFile } from 'node:fs/promises';\n```\n\n### Async File Operations\n```typescript\n// ❌ Error: no-sync\nconst data = fs.readFileSync('config.json');\n\n// ✅ Correct: Use async operations\nconst data = await fs.promises.readFile('config.json');\n```\n\n### Promise Handling\n```typescript\n// ❌ Error: no-floating-promises\nasync function processData() {\n  saveToDatabase(data); // Floating promise\n}\n\n// ✅ Correct: Handle the promise\nasync function processData() {\n  await saveToDatabase(data);\n  // or\n  void saveToDatabase(data); // Explicitly ignore\n}\n```\n\n## Special File Handling\n\n### Configuration Files\nRelaxed rules for `*.config.js` and `*.config.ts`:\n- Sync operations allowed\n- Environment variables permitted\n- Dynamic requires allowed\n\n### Test Files\nRelaxed security and type checking for `*.spec.ts` and `*.test.ts`:\n- Unpublished imports allowed (for test libraries)\n- Object injection warnings disabled\n- Any types permitted for mocking\n\n### Migration Scripts\nSpecial rules for `scripts/` and `migrations/` directories:\n- Console logging allowed\n- Process.exit permitted\n- File system warnings reduced\n\n## VSCode Integration\n\nAdd to `.vscode/settings.json`:\n\n```json\n{\n  \"editor.codeActionsOnSave\": {\n    \"source.fixAll.eslint\": \"explicit\"\n  },\n  \"eslint.experimental.useFlatConfig\": true,\n  \"eslint.validate\": [\n    \"javascript\",\n    \"typescript\"\n  ]\n}\n```\n\n## Package.json Scripts\n\n```json\n{\n  \"scripts\": {\n    \"lint\": \"eslint .\",\n    \"lint:fix\": \"eslint . --fix\",\n    \"lint:ci\": \"eslint . --max-warnings 0\",\n    \"lint:security\": \"eslint . --rule 'security/*: error'\",\n    \"type-check\": \"tsc --noEmit\"\n  }\n}\n```\n\n## Environment Variables\n\nFor projects using environment variables:\n\n```typescript\n// Create a typed env.ts file\nconst env = {\n  PORT: process.env.PORT || '3000',\n  NODE_ENV: process.env.NODE_ENV || 'development',\n  DATABASE_URL: process.env.DATABASE_URL!,\n} as const;\n\nexport default env;\n```\n\nThis pattern provides type safety while satisfying linter rules.\n\n## Performance Tips\n\n- Enable ESLint cache: `eslint . --cache`\n- Use `--max-warnings 0` in CI/CD pipelines\n- Consider disabling expensive rules in development:\n  ```javascript\n  const isDev = process.env.NODE_ENV === 'development';\n  export default [\n    ...nodeConfig,\n    {\n      rules: {\n        'security/detect-object-injection': isDev ? 'off' : 'warn',\n      }\n    }\n  ];\n  ```\n\n## Common Patterns\n\n### Error Handling\n```typescript\n// Recommended error class\nclass AppError extends Error {\n  constructor(\n    message: string,\n    public statusCode: number = 500,\n    public isOperational = true\n  ) {\n    super(message);\n    Error.captureStackTrace(this, this.constructor);\n  }\n}\n```\n\n### Async Middleware\n```typescript\n// Express async handler wrapper\nconst asyncHandler = (fn: RequestHandler): RequestHandler =\u003e {\n  return (req, res, next) =\u003e {\n    Promise.resolve(fn(req, res, next)).catch(next);\n  };\n};\n```\n\n## Migration from ESLint 8\n\n1. Remove `.eslintrc.*` files\n2. Create `eslint.config.js` with flat config\n3. Update to Node.js 20+ for full feature support\n4. Replace `eslint-plugin-node` with `eslint-plugin-n`\n5. Update scripts to use flat config\n\n## Philosophy\n\nThis configuration prioritizes:\n\n1. **Security** - Prevent vulnerabilities before they reach production\n2. **Performance** - Non-blocking operations and modern APIs\n3. **Type Safety** - Full TypeScript benefits for backend code\n4. **Modern Patterns** - Leverage Node.js 20+ capabilities\n5. **Developer Experience** - Clear errors with actionable fixes\n\n## License\n\nMIT\n\n## Contributing\n\nIssues and PRs welcome at [GitHub](https://github.com/stackvault/eslint-config-node)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackvault%2Feslint-config-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackvault%2Feslint-config-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackvault%2Feslint-config-node/lists"}