Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.14.2
22
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
FROM node:16.20.2-alpine AS builder
FROM node:22-alpine AS builder
RUN apk add --no-cache libc6-compat
RUN npm i -g pnpm@8.2.0
RUN npm i -g pnpm@9

# Create app directory
WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN pnpm install
COPY package*.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

COPY . .
RUN npm run build
RUN pnpm run build

FROM node:16.20.2-alpine
FROM node:22-alpine
RUN apk add --no-cache libc6-compat
RUN npm i -g pnpm@8.2.0
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist


EXPOSE 4000
CMD [ "npm", "run", "start" ]
104 changes: 82 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,98 @@
# Template node typescript
# Template Node.js TypeScript

A modern Node.js TypeScript template with a well-organized folder structure and best practices.

## Requirements

- Node.js 22.x (LTS)
- pnpm (recommended) or npm

## Getting Started

Instructions for installing dependencies and running the app locally.

```bash
npm install
npm run dev
# Install dependencies
pnpm install

# Run in development mode
pnpm run dev

# Build for production
pnpm run build

# Start production server
pnpm run start
```

## Project Structure
Overview of the project files and directories.

```
src/ - TypeScript source code
dist/ - Compiled JavaScript output
test/ - Unit tests
src/
├── config/ # Configuration files and environment variables
├── constants/ # Application constants and enums
├── middleware/ # Express/HTTP middleware functions
├── services/ # Business logic and service layer
├── shared/ # Shared utilities and helpers
├── types/ # TypeScript type definitions and interfaces
├── utils/ # Utility functions and helpers
└── index.ts # Application entry point

tests/ # Unit and integration tests
dist/ # Compiled JavaScript output (generated)
```

### Folder Descriptions

| Folder | Description |
|--------|-------------|
| `config/` | Environment configuration, app settings, and external service configs |
| `constants/` | Static values, HTTP status codes, error messages, and app-wide constants |
| `middleware/` | Request processing middleware (auth, logging, validation, etc.) |
| `services/` | Business logic layer with reusable service modules |
| `shared/` | Cross-cutting utilities shared across the application |
| `types/` | TypeScript interfaces, types, and type guards |
| `utils/` | Helper functions and utility modules |

## Scripts
Explanation of the main NPM scripts for development.

dev - Starts the app in development mode with live reloading
build - Compiles TypeScript to JavaScript
start - Runs the compiled app
test - Runs unit tests
Deployment
Notes on how to deploy the app to production.
| Script | Description |
|--------|-------------|
| `dev` | Starts the app in development mode with live reloading |
| `build` | Compiles TypeScript to JavaScript (CJS and ESM) |
| `start` | Runs the compiled app |
| `test` | Runs unit tests |
| `test:cov` | Runs tests with coverage report |
| `lint` | Runs ESLint to check and fix code style |
| `format` | Formats code using Prettier |

## Path Aliases

The project uses path aliases for cleaner imports:

```typescript
import { config } from '@/config';
import { HTTP_STATUS } from '@/constants';
import { getCurrentTimestamp } from '@/utils';
```

## Docker

Build and run the application using Docker:

```bash
docker build -t template-node-typescript .
docker run -p 8080:8080 template-node-typescript
```

## Built With

# Built With
Node.js - JavaScript runtime
TypeScript - Typed superset of JavaScript
# License
Overview of license used for the project.
- [Node.js](https://nodejs.org/) - JavaScript runtime (v22 LTS)
- [TypeScript](https://www.typescriptlang.org/) - Typed superset of JavaScript
- [Jest](https://jestjs.io/) - Testing framework
- [ESLint](https://eslint.org/) - Linting utility
- [Prettier](https://prettier.io/) - Code formatter

# Acknowledgments
Shoutouts to tutorials, libraries, and resources that were helpful.
## License

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.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@swc/helpers": "^0.5.1",
"@types/jest": "28.1.6",
"@types/lodash": "^4.14.197",
"@types/node": "^18.16.19",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "5.30.7",
"@typescript-eslint/parser": "5.30.7",
"concurrently": "^7.6.0",
Expand Down
Loading
Loading