flenco-node-backend-cli v0.1.10
Flenco Node Backend CLI
A powerful CLI tool to generate a production-ready Node.js backend boilerplate with Express, TypeScript, and Prisma. It automatically creates CRUD operations with validation, authentication, and file upload capabilities based on your existing database schema.
Features š
- š„ Fast project setup
- š TypeScript support
- š JWT Authentication
- š Prisma ORM integration
- ⨠Automatic CRUD generation
- š Request validation with Zod
- š Built-in pagination and sorting
- š ļø File upload support
- š§ Email service integration
- š Error handling
- šÆ Clean architecture
Prerequisites
- Node.js >= 14
- npm >= 6
- PostgreSQL or MySQL database
Installation
npm install -g flenco-node-backend-cli
Quick Start
1. Initialize a New Project
# Create a new directory for your project
mkdir my-backend
cd my-backend
# Initialize the project
flenco-init
During initialization, you'll be prompted for:
- Database type (PostgreSQL/MySQL)
- Database credentials
- Other configuration options
2. Generate APIs for Your Tables
flenco-generate
This will:
- Show available tables from your database
- Let you select a table
- Configure authentication and file upload options
- Generate complete CRUD operations
Project Structure
āāā src/
ā āāā routes/ # API routes
ā āāā controllers/ # Request handlers
ā āāā services/ # Business logic
ā āāā middleware/ # Custom middleware
ā āāā validation/ # Request validation
ā āāā utils/ # Utility functions
ā āāā templates/ # Email templates
āāā prisma/ # Prisma schema and migrations
āāā uploads/ # File uploads directory
āāā .env # Environment variables
Available Scripts
npm run dev # Start development server
npm run build # Build for production
npm start # Start production server
Generated API Endpoints
For each table, the following endpoints are created:
GET /api/{table} # Get all records (with pagination)
GET /api/{table}/:id # Get single record
POST /api/{table} # Create new record
PATCH /api/{table}/:id # Update record
DELETE /api/{table}/:id # Delete record
Query Parameters
page
: Page number (default: 1)limit
: Items per page (default: 10)sortBy
: Sort fieldsortOrder
: 'asc' or 'desc'search
: Search termstatus
: Filter by status
Configuration
The generated .env
file includes:
# Database
DATABASE_URL=your_database_url
PORT=3000
# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=1d
# Email (if needed)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your-email
SMTP_PASS=your-password
# File Upload
MAX_FILE_SIZE=5242880
ALLOWED_FILE_TYPES=image/jpeg,image/png,image/gif
Authentication
When enabled, protect routes using the JWT middleware:
router.use(auth());
Validation
Request validation is handled using Zod:
router.post('/', validate(createSchema), controller.create);
Error Handling
The generated project includes global error handling for:
- Validation errors
- Authentication errors
- Not found errors
- Database errors
- Unexpected errors
Commands
flenco-init
: Initialize a new projectflenco-generate
: Generate APIs for a tableflenco-help
: Show available commands
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Issues
If you find a bug or want to request a new feature, please create an issue at GitHub Issues.
Author
Atish Paul
License
MIT
Support
For support, email support@flenco.in or raise an issue on GitHub.