|
1 | | -# Template node typescript |
| 1 | +# Template Node.js TypeScript |
| 2 | + |
| 3 | +A modern Node.js TypeScript template with a well-organized folder structure and best practices. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +- Node.js 22.x (LTS) |
| 8 | +- pnpm (recommended) or npm |
2 | 9 |
|
3 | 10 | ## Getting Started |
| 11 | + |
4 | 12 | Instructions for installing dependencies and running the app locally. |
5 | 13 |
|
6 | 14 | ```bash |
7 | | -npm install |
8 | | -npm run dev |
| 15 | +# Install dependencies |
| 16 | +pnpm install |
| 17 | + |
| 18 | +# Run in development mode |
| 19 | +pnpm run dev |
| 20 | + |
| 21 | +# Build for production |
| 22 | +pnpm run build |
| 23 | + |
| 24 | +# Start production server |
| 25 | +pnpm run start |
9 | 26 | ``` |
10 | 27 |
|
11 | 28 | ## Project Structure |
12 | | -Overview of the project files and directories. |
13 | 29 |
|
14 | 30 | ``` |
15 | | -src/ - TypeScript source code |
16 | | -dist/ - Compiled JavaScript output |
17 | | -test/ - Unit tests |
| 31 | +src/ |
| 32 | +├── config/ # Configuration files and environment variables |
| 33 | +├── constants/ # Application constants and enums |
| 34 | +├── middleware/ # Express/HTTP middleware functions |
| 35 | +├── services/ # Business logic and service layer |
| 36 | +├── shared/ # Shared utilities and helpers |
| 37 | +├── types/ # TypeScript type definitions and interfaces |
| 38 | +├── utils/ # Utility functions and helpers |
| 39 | +└── index.ts # Application entry point |
| 40 | +
|
| 41 | +tests/ # Unit and integration tests |
| 42 | +dist/ # Compiled JavaScript output (generated) |
18 | 43 | ``` |
| 44 | + |
| 45 | +### Folder Descriptions |
| 46 | + |
| 47 | +| Folder | Description | |
| 48 | +|--------|-------------| |
| 49 | +| `config/` | Environment configuration, app settings, and external service configs | |
| 50 | +| `constants/` | Static values, HTTP status codes, error messages, and app-wide constants | |
| 51 | +| `middleware/` | Request processing middleware (auth, logging, validation, etc.) | |
| 52 | +| `services/` | Business logic layer with reusable service modules | |
| 53 | +| `shared/` | Cross-cutting utilities shared across the application | |
| 54 | +| `types/` | TypeScript interfaces, types, and type guards | |
| 55 | +| `utils/` | Helper functions and utility modules | |
| 56 | + |
19 | 57 | ## Scripts |
20 | | -Explanation of the main NPM scripts for development. |
21 | 58 |
|
22 | | -dev - Starts the app in development mode with live reloading |
23 | | -build - Compiles TypeScript to JavaScript |
24 | | -start - Runs the compiled app |
25 | | -test - Runs unit tests |
26 | | -Deployment |
27 | | -Notes on how to deploy the app to production. |
| 59 | +| Script | Description | |
| 60 | +|--------|-------------| |
| 61 | +| `dev` | Starts the app in development mode with live reloading | |
| 62 | +| `build` | Compiles TypeScript to JavaScript (CJS and ESM) | |
| 63 | +| `start` | Runs the compiled app | |
| 64 | +| `test` | Runs unit tests | |
| 65 | +| `test:cov` | Runs tests with coverage report | |
| 66 | +| `lint` | Runs ESLint to check and fix code style | |
| 67 | +| `format` | Formats code using Prettier | |
| 68 | + |
| 69 | +## Path Aliases |
| 70 | + |
| 71 | +The project uses path aliases for cleaner imports: |
| 72 | + |
| 73 | +```typescript |
| 74 | +import { config } from '@/config'; |
| 75 | +import { HTTP_STATUS } from '@/constants'; |
| 76 | +import { getCurrentTimestamp } from '@/utils'; |
| 77 | +``` |
| 78 | + |
| 79 | +## Docker |
| 80 | + |
| 81 | +Build and run the application using Docker: |
| 82 | + |
| 83 | +```bash |
| 84 | +docker build -t template-node-typescript . |
| 85 | +docker run -p 8080:8080 template-node-typescript |
| 86 | +``` |
| 87 | + |
| 88 | +## Built With |
28 | 89 |
|
29 | | -# Built With |
30 | | -Node.js - JavaScript runtime |
31 | | -TypeScript - Typed superset of JavaScript |
32 | | -# License |
33 | | -Overview of license used for the project. |
| 90 | +- [Node.js](https://nodejs.org/) - JavaScript runtime (v22 LTS) |
| 91 | +- [TypeScript](https://www.typescriptlang.org/) - Typed superset of JavaScript |
| 92 | +- [Jest](https://jestjs.io/) - Testing framework |
| 93 | +- [ESLint](https://eslint.org/) - Linting utility |
| 94 | +- [Prettier](https://prettier.io/) - Code formatter |
34 | 95 |
|
35 | | -# Acknowledgments |
36 | | -Shoutouts to tutorials, libraries, and resources that were helpful. |
| 96 | +## License |
37 | 97 |
|
38 | | -Let me know if you would like me to expand or modify this suggested README. I aimed to provide a high-level overview based on the context provided. |
| 98 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments