|
1 | 1 | # TypeScript Template |
2 | 2 |
|
3 | | -This is a template repository for starting a new TypeScript project. |
| 3 | +A modern, minimal template for starting TypeScript projects on Node.js with sensible defaults and a smooth developer experience. |
4 | 4 |
|
5 | | -## Getting Started |
| 5 | +## Features |
6 | 6 |
|
7 | | -### Prerequisites |
| 7 | +- TypeScript 5 with strict mode and Node LTS (22) aligned config |
| 8 | +- Fast iteration using `ts-node` for development |
| 9 | +- ESLint (typescript-eslint) and Prettier for consistent, high‑quality code |
| 10 | +- Environment variables via `dotenv` |
| 11 | +- Dependency management with `pnpm` |
8 | 12 |
|
9 | | -- [Node.js](https://nodejs.org/) |
10 | | -- [pnpm](https://pnpm.io/) |
| 13 | +## Prerequisites |
11 | 14 |
|
12 | | -### Installation |
| 15 | +- Node.js 20 or 22+ (LTS recommended) |
| 16 | +- pnpm 10+ |
13 | 17 |
|
14 | | -1. Clone the repository: |
| 18 | +## Quick Start |
15 | 19 |
|
16 | | - ```sh |
17 | | - git clone https://github.com/your-username/typescript-template.git |
18 | | - cd typescript-template |
19 | | - ``` |
| 20 | +- Clone and install dependencies: |
20 | 21 |
|
21 | | -2. Install dependencies using pnpm: |
| 22 | +```sh |
| 23 | +git clone https://github.com/sajaddp/typescript-template.git |
| 24 | +cd typescript-template |
| 25 | +pnpm i |
| 26 | +``` |
22 | 27 |
|
23 | | - ```sh |
24 | | - pnpm i |
25 | | - ``` |
| 28 | +- Configure environment variables: |
26 | 29 |
|
27 | | -### Running the Project |
| 30 | +- Create a `.env` file in the project root (if it doesn’t exist) and set: |
28 | 31 |
|
29 | | -To run the project, use the following command: |
| 32 | +```env |
| 33 | +MY_SECRET="your-secret-value" |
| 34 | +``` |
| 35 | + |
| 36 | +- Run in development mode: |
30 | 37 |
|
31 | 38 | ```sh |
32 | | -ts-node ./src/index.ts |
| 39 | +pnpm dev |
33 | 40 | ``` |
34 | 41 |
|
35 | | -### Development |
| 42 | +The app logs the value of `MY_SECRET` to the console. |
36 | 43 |
|
37 | | -To start the development server, run: |
| 44 | +## Scripts |
38 | 45 |
|
39 | | -```sh |
40 | | -npm run dev |
41 | | -``` |
| 46 | +- `pnpm dev`: Run the app with `ts-node` from `src/index.ts`. |
| 47 | +- `pnpm build`: Compile TypeScript with `tsc`. |
| 48 | +- `pnpm prettier`: Format code in `src` using Prettier. |
42 | 49 |
|
43 | | -### Code Formatting |
| 50 | +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`. |
44 | 51 |
|
45 | | -To format the code using Prettier, run: |
| 52 | +## Project Structure |
46 | 53 |
|
47 | | -```sh |
48 | | -npm run prettier |
| 54 | +```txt |
| 55 | +. |
| 56 | +├── src/ |
| 57 | +│ └── index.ts # Entry point (example: reading an env variable) |
| 58 | +├── eslint.config.mjs # ESLint configuration with typescript-eslint |
| 59 | +├── tsconfig.json # TypeScript configuration aligned with Node 22 |
| 60 | +├── package.json # Scripts and dependencies |
| 61 | +├── .env # Local environment variables |
| 62 | +└── README.MD |
49 | 63 | ``` |
50 | 64 |
|
| 65 | +## Code Quality |
| 66 | + |
| 67 | +- ESLint: Lint TypeScript/JS code |
| 68 | + |
| 69 | + ```sh |
| 70 | + pnpm exec eslint . --ext .ts |
| 71 | + ``` |
| 72 | + |
| 73 | +- Prettier: Enforce consistent formatting |
| 74 | + |
| 75 | + ```sh |
| 76 | + pnpm prettier |
| 77 | + ``` |
| 78 | + |
| 79 | +## TypeScript Settings |
| 80 | + |
| 81 | +- Target: `es2023` |
| 82 | +- Module/Resolution: `node16` |
| 83 | +- Enabled: `strict: true`, `esModuleInterop: true`, `resolveJsonModule: true` |
| 84 | + |
| 85 | +To emit compiled files into a separate directory, enable `outDir` in `tsconfig.json`. |
| 86 | + |
| 87 | +## Troubleshooting |
| 88 | + |
| 89 | +- Missing env value: Ensure `.env` exists and `MY_SECRET` is defined, then run with `pnpm dev`. |
| 90 | +- Where is the build output? Without `outDir`, `.js` files are emitted next to `.ts`. Either run `node src/index.js` or configure `outDir` (e.g., `dist`) and run `node dist/index.js`. |
| 91 | + |
51 | 92 | ## License |
52 | 93 |
|
53 | | -This project is licensed under the MIT License. |
| 94 | +Released under the MIT License. |
0 commit comments