- name
- nodejs-typescript-foundation
- description
- Sets the baseline tooling and tsconfig for any Node.js TypeScript project: strict compiler flags, ESLint, Prettier, package layout, npm scripts. Use when bootstrapping a new project or auditing an existing one for foundational quality.
# Node.js TypeScript Foundation
## When to use
- Bootstrapping a new Node.js TypeScript project
- Auditing an existing project's foundational tooling
- Adding strict type-checking and linting
## Core rules
1. `tsconfig.json` must enable `strict: true`, `noImplicitAny: true`, `strictNullChecks: true`
2. ESLint with `@typescript-eslint` parser, no `any`, no `console.log` in production
3. Prettier for formatting, integrated with ESLint
4. Package layout: `src/`, `dist/`, `tests/`, npm scripts for build/lint/test
5. All third-party libs must have `@types/*` packages installed
## Reference shape (TypeScript)
### tsconfig.json
```json
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
}
```
### ESLint config (.eslintrc.json)
```json
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
```
## Examples — Do
```typescript
// Strict typing, explicit returns
class UserService {
constructor(private readonly repository: UserRepository) {}
async findById(id: string): Promise<User | null> {
return this.repository.findById(id);
}
}
```
## Examples — Don't
```typescript
// ❌ any, no typing
function getUser(id) {
return db.query(`SELECT * FROM users WHERE id = ${id}`);
}
```
## Checklist
- [ ] `tsconfig.json` with strict flags
- [ ] ESLint + Prettier configured
- [ ] npm scripts: `build`, `lint`, `test`, `dev`
- [ ] `.gitignore` with `node_modules/`, `dist/`
- [ ] `src/` and `tests/` folders created
See [reference/foundation-setup.md](./reference/foundation-setup.md) for full setup guide.
View on GitHub