TypeScript (NestJS)
The TypeScript template uses NestJS, a progressive Node.js framework for building efficient and scalable server-side applications.
Overview
| Component | Technology |
|---|---|
| Framework | NestJS 10 |
| ORM | TypeORM |
| Validation | class-validator |
| Documentation | Swagger/OpenAPI |
| Testing | Jest |
Quick Start
# Create a new TypeScript service
apso server new my-api --template typescript
# Navigate to project
cd my-api
# Install dependencies
npm install
# Start development server
npm run devProject Structure
my-api/
βββ src/
β βββ entities/ # TypeORM entities
β β βββ project.entity.ts
β β βββ task.entity.ts
β βββ modules/ # NestJS modules
β β βββ projects/
β β β βββ projects.module.ts
β β β βββ projects.controller.ts
β β β βββ projects.service.ts
β β β βββ dto/
β β βββ tasks/
β βββ extensions/ # Your custom code
β β βββ controllers/
β β βββ services/
β β βββ modules/
β βββ common/ # Shared utilities
β β βββ decorators/
β β βββ guards/
β β βββ interceptors/
β βββ config/ # Configuration
β βββ app.module.ts
β βββ main.ts
βββ test/ # E2E tests
βββ .apsorc # APSO schema
βββ package.json
βββ tsconfig.jsonKey Technologies
NestJS
NestJS provides a robust architecture with:
- Modules for code organization
- Controllers for HTTP handling
- Services for business logic
- Dependency injection
- Middleware and guards
TypeORM
Type-safe database access:
- Entity definitions
- Migrations
- Query builder
- Repository pattern
Class-Validator
Request validation with decorators:
import { IsString, IsNotEmpty, MaxLength } from 'class-validator';
export class CreateProjectDto {
@IsString()
@IsNotEmpty()
@MaxLength(200)
name: string;
@IsString()
@IsOptional()
description?: string;
}Configuration
Environment Variables
# .env
DATABASE_URL=postgresql://user:pass@localhost:5432/db
JWT_SECRET=your-secret-key
PORT=3001
NODE_ENV=developmentTypeORM Configuration
// src/config/database.config.ts
export const databaseConfig = {
type: 'postgres',
url: process.env.DATABASE_URL,
entities: [__dirname + '/../entities/*.entity{.ts,.js}'],
migrations: [__dirname + '/../migrations/*{.ts,.js}'],
synchronize: process.env.NODE_ENV === 'development',
};Commands
| Command | Description |
|---|---|
npm run dev | Start with hot reload |
npm run build | Build for production |
npm start | Start production server |
npm test | Run unit tests |
npm run test:e2e | Run E2E tests |
npm run lint | Lint code |
Features
Auto-Generated
- Entity definitions with TypeORM decorators
- CRUD controllers with validation
- Services with repository injection
- DTOs for create/update operations
- Swagger documentation
- Basic authentication guards
Customizable
- Add custom endpoints in extensions
- Override generated services
- Add middleware and guards
- Integrate external services
Next Steps
Last updated on