@ahmdhndrsyh/nestjs-starter
v0.0.9
Published
Basic starter project for building scalable and maintainable NestJS applications, equipped with developer-friendly tooling and CI-ready setup.
Readme
NestJS Starter ⚡️
Basic starter project for building scalable and maintainable NestJS applications, equipped with developer-friendly tooling and CI-ready setup.
✨ Features
- 🚀 Built with NestJS
- 📦 Auto-import sorting via
@trivago/prettier-plugin-sort-imports - 📋 Pre commit with Husky and commit linting with Conventional Commits
- 📝 Logger with Pino
- ✅ CI Workflows for type checking & linting
Check
.github/workflows/ci.ymlfor more details. - 🔒 Type safe environment variables.
- 📄 Swagger Docs
📦 Getting Started
This starter template assumes you are using pnpm as your package manager. Of course, pnpm and npm can be used interchangeably.
npx @ahmdhndrsyh/nestjs-starter my-app
cd my-app
mv env.example .env
pnpm start:dev
mvis aUnixcommand and if you're come fromWindows, you have 2 options:
- Installing
Git Bashand usemvcommand in thebash- Using Windows
movecommand.
📋 Git Hooks & Commit Rules
This starter uses:
Conventional commit examples:
feat(auth): add JWT strategy
fix(core): fix logger context issue
chore: update dependencies🔒 Type Safe Env Variables
This starter uses Zod for validating your environment variables. You can define your environment variables in the src/core/config/env.schema.ts file.
Example:
import { z } from 'zod';
export const envSchema = z.object({
NODE_ENV: z.enum(['development', 'production']), // defined in the schema but forgot added to the .env file
PORT: z.string().transform(Number).default('3000'),
// Add more environment variables as needed
});it will be validated at runtime and will throw an error if the validation fails.
❌ Invalid environment variables:
{ _errors: [], NODE_ENV: { _errors: [ 'Required' ] } }📄 Swagger Docs
This starter includes Swagger documentation for your API endpoints. You can access the API documentation at http://localhost:3000/docs or change to your preferred url in the main.ts file.
Here is an example of how to use it:
// app.controller.ts
@Post() // Method Decorator
@ApiParam({ name: 'message', description: 'Message to be sent' }) // Document the parameters present in the URL path
@ApiBody({ // Document the content of the request body
schema: {
type: 'object',
properties: {
fullName: { type: 'string', example: 'John' },
},
},
})
greeting(
@Body(new ZodValidationPipe(greetingSchema)) greetingDto: GreetingDto,
) {
return this.appService.greeting(greetingDto);
}Visit NestJS Swagger Docs for more information.
🔧 Tooling
| Tool | Purpose |
| ------------------------- | --------------------------------------- |
| pino | Fast, structured logging |
| prettier + sort-imports | Auto-format + sort imports |
| eslint | Lint codebase |
| husky + commitlint | Enforce clean commit messages |
| GitHub Actions | Run Type Check & Linter on pull request |
MIT License
This project is licensed under the MIT License. See the MIT file for details.
