Production-ready Express + TypeScript/JavaScript backend generator with optional features and microservice support
npm install @ifecodes/backend-templatebash
npx @ifecodes/backend-template my-project
`
Or install globally:
`bash
npm install -g @ifecodes/backend-template
ifecodes-template my-project
`
$3
`bash
Create a monolith
npx @ifecodes/backend-template my-api mono
Create a microservice
npx @ifecodes/backend-template my-project micro
`
---
š§ Interactive Setup
When you run the CLI, you'll be prompted to choose:
$3
- TypeScript (default) - Full type safety and modern tooling
- JavaScript - Transpiled from TypeScript for simplicity
$3
- Description - Project description for package.json
- Author - Your name or organization
- Keywords - Comma-separated keywords for discoverability
$3
- Monolith API - Traditional single-server architecture
- Microservice - Distributed services with API Gateway
$3
- Docker - Container-based deployment with docker-compose
- PM2 - Process manager for Node.js applications
$3
- ā
CORS - Cross-Origin Resource Sharing
- ā
Helmet - Security headers middleware
- ā
Rate Limiting - API request throttling
- ā
Morgan - HTTP request logger
$3
- ā
JWT Authentication with MongoDB
- Choose between bcrypt (recommended for Windows) or argon2 for password hashing
---
š Project Structure
$3
`
my-backend/
āāā src/
ā āāā config/ # Configuration files
ā āāā middlewares/ # Custom middlewares
ā āāā modules/ # Feature modules
ā ā āāā v1/ # API version 1
ā ā āāā auth/ # Auth module (if enabled)
ā ā āāā health/ # Health check
ā āāā models/ # Database models (if auth)
ā āāā utils/ # Utility functions
ā āāā app.ts # Express app setup
ā āāā routes.ts # Route definitions
ā āāā server.ts # Server entry point
āāā .husky/ # Git hooks
āāā .env # Environment variables
āāā package.json
āāā tsconfig.json
`
$3
`
my-project/
āāā shared/ # Shared utilities across services
ā āāā config/ # Environment configs (db.ts only if auth enabled)
ā āāā utils/ # Logger, error handlers
āāā services/
ā āāā gateway/ # API Gateway (port 4000)
ā āāā health-service/ # Health checks (port 4001)
ā āāā auth-service/ # Authentication (port 4002, if enabled)
āāā docker-compose.yml # Docker setup (if selected)
āāā pm2.config.js # PM2 setup (if selected)
āāā .env # Root environment variables
āāā .gitignore # Git ignore (includes .env and node_modules)
āāā tsconfig.json # Root TypeScript config with project references
āāā .husky/ # Git hooks
āāā package.json # Root package.json
`
Note: Each microservice does NOT have its own .env file. Environment variables are managed at the root level through docker-compose.yml or pm2.config.js.
---
ā¶ļø Running the Application
$3
`bash
cd my-backend
Development
npm run dev
Production
npm run build
npm start
`
$3
`bash
cd my-project
Start all services
docker-compose up
Start in detached mode
docker-compose up -d
View logs
docker-compose logs -f
Stop all services
docker-compose down
`
$3
`bash
cd my-project
Start all services
pm2 start pm2.config.js
View logs
pm2 logs
Monitor services
pm2 monit
Stop all services
pm2 stop all
`
---
š Tech Stack
- Runtime: Node.js (v18+)
- Language: TypeScript or JavaScript
- Framework: Express.js
- Database: MongoDB (with Mongoose, if auth enabled)
- Authentication: JWT + bcrypt/argon2
- Security: Helmet, CORS, Rate Limiting
- Logging: Morgan, Custom Logger
- Git Hooks: Husky
- Deployment: Docker or PM2
---
TypeScript vs JavaScript
This CLI generates TypeScript projects by default but also includes explicit JavaScript templates. There is no fragile, on-the-fly TypeScript ā JavaScript transform at runtime ā the project templates include language-specific variants so the output is predictable and parseable in Node.js.
$3
- Full type safety and IntelliSense
- Modern ECMAScript features
- Compile-time error checking
- Better tooling and refactoring support
$3
- Pre-authored JavaScript (CommonJS) templates are included
- No TypeScript annotations remain in generated .js files
- DevDependencies that are TypeScript-only are omitted for JS projects
- Same functionality with simpler runtime setup
---
š Features
$3
- Auto-generates README with project-specific instructions
- Creates .env from .env.example with default values
- Configures TypeScript paths for clean imports (@/config, @/utils)
- Project metadata (description, author, keywords) in package.json
$3
- API Gateway on port 4000 (single entry point)
- Service Discovery - Automatically routes to correct service
- Shared Folder - Common utilities across all services
- Health Checks - Built-in monitoring endpoints
$3
- Hot Reload - Development server with nodemon
- ESLint - Code quality enforcement
- Git Hooks - Pre-commit linting with Husky
- Type Safety - Full TypeScript support
---
š” API Endpoints
$3
`
GET / - API information
GET /api/v1/health - Health check
POST /api/v1/auth/register - Register user (if auth enabled)
POST /api/v1/auth/login - Login user (if auth enabled)
`
$3
All requests go through the API Gateway at http://localhost:4000
`
GET /health - Gateway health check
GET /api/v1/health - Health service check
POST /api/v1/auth/register - Auth service (if enabled)
POST /api/v1/auth/login - Auth service (if enabled)
`
---
š§ Environment Variables
$3
`env
PORT=4000
NODE_ENV=development
`
$3
`env
NODE_ENV=development
Gateway Service
GATEWAY_PORT=4000
Health Service
HEALTH_SERVICE_PORT=4001
Auth Service (if enabled)
AUTH_SERVICE_PORT=4002
`
Note: Microservices use environment variables from docker-compose.yml or pm2.config.js. Individual services don't have .env files.
$3
`env
ALLOWED_ORIGIN=http://localhost:3000
`
$3
`env
MONGO_URI=mongodb://localhost:27017/your-database-name
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
`
---
š Adding Services (Microservice)
You can add more services to an existing microservice project:
`bash
cd my-project
npx @ifecodes/backend-template
You'll be prompted to name the new service
Example: user-service, order-service, etc.
`
The CLI will:
- Create the new service
- Update docker-compose.yml or pm2.config.js
- Configure routing in the API Gateway
---
š¤ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
$3
`bash
git clone https://github.com/ALADETAN-IFE/backend-template.git
cd backend-template
npm install
npm link
``