backend-starter-toolkit
v1.0.15
Published
A minimal Node.js + TypeScript backend starter template and CLI tool using Express, Pino logging, validation middleware, 404 + error handling, and fast development cycle.
Readme
backend-starter-toolkit
A minimal Node.js + TypeScript backend starter template and CLI tool using Express, Pino logging, validation middleware, 404 + error handling, and fast development cycle.
✅ Features
- Express server with
src/app.tsandsrc/server.ts - root endpoint:
GET /returns "Hello World!" - configurable via
.env(development/staging/production) - logging with
pino+rotating-file-stream - security middleware:
helmet,cors - centralized error handling + 404 not found
- utility module
sumwith Vitest unit tests - linting, formatting, commit hooks, and type-checking workflows
�📦 Requirements
- Node.js 25.x (or latest compatible)
pnpm(project usespnpmpackage manager)
�️ Usage with NPX
Quick start with npx (no installation required):
npx backend-starter-toolkitThis command bootstraps a new backend project with all the starter template features. Additional options:
npx backend-starter-toolkit --help # Show all available commands
npx backend-starter-toolkit --version # Show version⚠️ Warning: Do NOT use npm i backend-starter-toolkit. Always use npx backend-starter-toolkit for the best experience with proper dependency management.
��� Install dependencies
pnpm install🛠️ Environment
Copy and set environment variables for your environment.
cp .env.example .env.development
cp .env.example .env.staging
cp .env.example .env.productionEnvironment Variables
PORT: The port number on which the Express server will listen (e.g.,3000)SERVER_URL: The base URL of the server (e.g.,http://localhost:3000)ENV: The environment mode, one ofdevelopment,staging, orproductionDATABASE_URL: The database connection string (optional; required if using a database)
▶️ Development
pnpm dev
pnpm dev:staging
pnpm dev:prodExpress server starts and logs via Pino. Root route is at GET /.
🧱 Build
pnpm buildBuild compiles with TypeScript using tsconfig.build.json.
🧪 Tests
pnpm test:run
pnpm test:ui
pnpm coverageIncludes sample unit test in src/__tests__/sum.spec.ts for src/utils/sum.ts.
🎯 Lint & formatter
pnpm lint
pnpm lint:fix
pnpm format
pnpm format:checkGit hooks via husky and lint-staged run lint + prettier before commit.
📁 Project structure
src/app.ts- Express app setupsrc/server.ts- server startup + graceful shutdownsrc/config/config.ts- env config loadersrc/middlewares/middlewares.ts- sample route handlersrc/middlewares/notFound.ts- 404 middlewaresrc/middlewares/globalErrorHandler.ts- error handlersrc/utils/logger.ts- pino logger config + file rotationsrc/utils/httpError.ts- http error wrappersrc/utils/errorObjects.ts- error response buildersrc/constant/*- response messages + environment enumssrc/type/types.ts- TS type definitionssrc/__tests__- unit tests
Middleware flow
pino-httplogs request/responseexpress.jsonparses incoming JSONcorsenables CORShelmetadds security headersexpress.staticservespublic/globalErrorHandlerhandles errors in JSON formatnotFoundhandles unknown routes
🧩 Tool usecases
pnpm: package install, script runner, workspace managementtsx: run TypeScript directly without build step (dev server)typescript/tsc: type-checking and production build (pnpm build)express: web framework and routingdotenv: environment config from.envfileshelmet: security best-practice headerscors: cross-origin resource sharingpino,pino-http,pino-pretty: structured logs + prettified dev logsrotating-file-stream: daily log rotation inlogs/vitest: testing framework (test/coverage)eslint,@commitlint,prettier: code quality and style enforcementhusky,lint-staged: commit hooks and pre-commit lint/formatnpm-check-updates(ncu): check and update outdated dependencies
🤝 Contributing
- Fork and branch
pnpm install- Add tests
- Run lint/format
- Open PR
🆘 Troubleshooting
- Port in use: change
PORTin.env - Type errors:
pnpm type-check - Commit blocked: run
pnpm lint:fixandpnpm format
