A modern, minimal template for starting TypeScript projects on Node.js with sensible defaults and a smooth developer experience.
- TypeScript 5 with strict mode and Node LTS (22) aligned config
- Fast iteration using
ts-nodefor development - Biome (formatter + linter) for consistent, high-quality code
- Environment variables via
dotenv - Dependency management with
pnpm
- Node.js 20 or 22+ (LTS recommended)
- pnpm 10+
- Clone and install dependencies:
git clone https://github.com/sajaddp/typescript-template.git cd typescript-template pnpm i-
Configure environment variables:
-
Create a
.envfile in the project root (if it doesn’t exist) and set:
MY_SECRET="your-secret-value"- Run in development mode:
pnpm devThe app logs the value of MY_SECRET to the console.
pnpm dev: Run the app withts-nodefromsrc/index.ts.pnpm build: Compile TypeScript withtsc.pnpm format: Format codebase with Biome's formatter.pnpm lint: Run Biome in safe mode (formats and sorts imports).pnpm lint:unsafe: Run Biome with unsafe fixes (also removes unused imports).
Note: After pnpm build, JavaScript output is emitted alongside the .ts files by default. You can set outDir in tsconfig.json (e.g., dist) and then run node dist/index.js.
. ├── src/ │ └── index.ts # Entry point (example: reading an env variable) ├── biome.json # Biome configuration for formatting and lint checks ├── tsconfig.json # TypeScript configuration aligned with Node 22 ├── package.json # Scripts and dependencies ├── .env # Local environment variables └── README.MD-
Biome (safe): Format and sort imports
pnpm lint
-
Biome (unsafe): Apply safe fixes and remove unused imports
pnpm lint:unsafe
-
Formatter-only:
pnpm format
- Target:
es2023 - Module/Resolution:
node16 - Enabled:
strict: true,esModuleInterop: true,resolveJsonModule: true
To emit compiled files into a separate directory, enable outDir in tsconfig.json.
- Missing env value: Ensure
.envexists andMY_SECRETis defined, then run withpnpm dev. - Where is the build output? Without
outDir,.jsfiles are emitted next to.ts. Either runnode src/index.jsor configureoutDir(e.g.,dist) and runnode dist/index.js.
Released under the MIT License.