0.1.10 • Published 7 months ago

flenco-node-backend-cli v0.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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.

NPM Downloads License TypeScript PRs Welcome Buy Me A Coffee

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 field
  • sortOrder: 'asc' or 'desc'
  • search: Search term
  • status: 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 project
  • flenco-generate: Generate APIs for a table
  • flenco-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.

"Buy Me A Coffee"

0.1.10

7 months ago

0.1.9

7 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.6

7 months ago

0.1.5

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago