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-node
for development - ESLint (typescript-eslint) and Prettier 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
.env
file in the project root (if it doesn’t exist) and set:
MY_SECRET="your-secret-value"
- Run in development mode:
pnpm dev
The app logs the value of MY_SECRET
to the console.
pnpm dev
: Run the app withts-node
fromsrc/index.ts
.pnpm build
: Compile TypeScript withtsc
.pnpm prettier
: Format code insrc
using Prettier.
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) ├── eslint.config.mjs # ESLint configuration with typescript-eslint ├── tsconfig.json # TypeScript configuration aligned with Node 22 ├── package.json # Scripts and dependencies ├── .env # Local environment variables └── README.MD
-
ESLint: Lint TypeScript/JS code
pnpm exec eslint . --ext .ts
-
Prettier: Enforce consistent formatting
pnpm prettier
- 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
.env
exists andMY_SECRET
is defined, then run withpnpm dev
. - Where is the build output? Without
outDir
,.js
files are emitted next to.ts
. Either runnode src/index.js
or configureoutDir
(e.g.,dist
) and runnode dist/index.js
.
Released under the MIT License.