Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (create-node-backend-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
create-node-backend-ts
A CLI tool to scaffold a complete Node.js + TypeScript backend with modern best practices.
Generate a ready-to-use backend with:
- Express for HTTP server
- TypeScript with strict typing
- MongoDB integration using Mongoose
- Logging via Winston with daily rotated logs
- Global Error Handler for centralized error management
- Async Handler Wrapper to simplify async route handling
- Environment Configuration via .env files
- Request Validation using Joi
- Organized Route / Controller / Service / Model structure
Perfect for rapid backend project setup with minimal boilerplate.
🚀 Installation (No global install needed)
Run the generator using npx:
npx create-node-backend-ts my-backendOr using yarn:
yarn create node-backend my-backendOr using pnpm:
pnpm dlx create-node-backend-ts my-backendmy-backend will be the folder name of your new project.
📦 After Generating Project
cd my-backend # Go into your project folder
npm install # Install dependencies
npm run dev # Start the development serverDevelopment mode uses tsx watch (if configured) or ts-node-dev.
Logs will be written to the logs/ folder, with console output only in development.
🗂 Project Structure
Example of the generated backend structure:
my-backend/
├─ logs/ # Rotated log files
├─ src/
│ ├─ controllers/ # Route handlers
│ ├─ services/ # Business logic
│ ├─ routes/ # API routes
│ ├─ models/ # Mongoose models
│ ├─ middlewares/ # Error handler, async wrapper
│ ├─ utils/ # Logger, helpers, etc.
│ └─ server.ts # Entry point
├─ package.json
├─ tsconfig.json
├─ .env # Environment variables
└─ README.md⚡ CLI Module Generation
After creating your project, you can generate boilerplate module files for any feature:
npx create-node-backend-ts --generate <module-name>For example:
npx create-node-backend-ts --generate productThis will automatically create the following files:
src/controllers/product.controller.ts
src/models/product.model.ts
src/services/product.service.ts
src/routes/product.routes.tsReplace product with any module name to scaffold the boilerplate automatically.
⚙ Features
Global Error Handling
All errors in routes are caught and sent in a structured JSON format.
Async Route Wrapper
Avoid repetitive try-catch blocks in async routes.
Validation with Joi
Request payloads can be validated easily with reusable schemas.
Logging with Winston
- Daily rotated log files (
logs/) - Console logging only in development mode
Environment Variables
Load .env files automatically with dotenv.
💡 Tips
- Add .env for sensitive configs like MONGO_URI, PORT, etc.
- In production, use file logs only; console logs are for development.
- Extend controllers, services, models, and routes as needed — template is modular and CLI-assisted.
Use the CLI to generate any module at any time after project creation.