JSPM

  • Created
  • Published
  • Downloads 56
  • Score
    100M100P100Q63409F
  • License MIT

Universal CRUD Generator - Express.js plugin and CLI tool for generating Node.js CRUD APIs with database models, controllers, and admin interface

Package Exports

  • ucg
  • ucg/index.js

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 (ucg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

UCG - Universa```bash

Global installation (for CLI)

const express = require('express');
const ucg = require('ucg');

const app = express();
app.use(express.json());

// Initialize UCG plugin
const uc- **GET** `/api/users/:id` - Get user by ID with relational data
- **POST** `/api/users` - Create new user with validation
- **PUT** `/api/users/:id` - Update user
- **DELETE** `/api/users/:id` - Delete user

## 🛠️ Troubleshooting

### Common Issues

#### 1. API Routes Return 404 Errors

**Symptoms**: Generated routes appear in Swagger docs but return 404 when accessed.

**Causes & Solutions**:

- **Sequelize Alias Conflicts**: Multiple foreign keys to the same table using identical aliases.
  ```bash
  # Error message:
  # "You have used the alias 'questions' in two separate associations"

Solution: UCG v1.1.5+ automatically generates unique aliases. Update your UCG version:

npm update ucg
  • Route Mounting Issues: Routes not properly integrated into Express app. Solution: Ensure autoRegisterRoutes: true is set and restart your server.

2. CORS Errors in Swagger UI

Symptoms: "Failed to fetch" errors when testing APIs in Swagger documentation.

Solution: Add CORS middleware to your Express app:

const cors = require('cors');

app.use(cors({
  origin: true,
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With']
}));

3. Database Connection Issues

Symptoms: UCG admin interface shows database connection errors.

Solutions:

  • Verify database credentials in UCG setup
  • Ensure database server is running
  • Check network connectivity to database host

Getting Help

If you encounter issues:

  1. Check the GitHub Issues
  2. Review the error logs in your console
  3. Ensure you're using the latest UCG version: npm update ucg

🤝 Contributingn = ucg({ll -g ucg

Local installation (for plugin use)

npm install ucg


### CLI Usage

```bash
# Initialize UCG in your project
ucg init

# Start the admin interface
ucg start

# Generate CRUD operations
ucg generate:crud --model User
```Express.js plugin and CLI tool for generating Node.js CRUD APIs with database models, controllers, and admin interface**

[![npm version](https://badge.fury.io/js/ucg.svg)](https://badge.fury.io/js/ucg) - Node CRUD Generator

**Express.js plugin and CLI tool for generating Node.js CRUD APIs with database models, controllers, and admin interface**

[![npm version](https://badge.fury.io/js/ucg.svg)](https://badge.fury.io/js/ucg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen.svg)](https://nodejs.org/)

## 🚀 Quick Start

### Installation

```bash
# Global installation (for CLI)
npm install -g ucg

# Local installation (for plugin use)
npm install ucg

Quick Setup (Fastest Way)

# One-command setup - creates a new project with UCG
npx ucg quick-setup --name my-api

# With custom database
npx ucg quick-setup --name my-api --db postgres

# Navigate to your project and start
cd my-api
npm start

CLI Usage

# Initialize UCG in your project
ucg init

# Start the admin interface
ucg start

# Generate CRUD operations
ucg generate:crud --model User

Plugin Usage

UCG supports two API patterns for flexibility:

const express = require('express');
const ucg = require('ucg');

const app = express();
app.use(express.json());

// Initialize UCG plugin
const ucgPlugin = ucg({
  mountPath: '/admin',
  autoRegisterRoutes: true
});

app.use('/admin', ucgPlugin.initialize(app));

app.listen(3000, () => {
  console.log('🚀 Server running on http://localhost:3000');
  console.log('📊 UCG Admin at http://localhost:3000/admin');
});

Pattern 2: Class Instantiation

const express = require('express');
const { UCGPlugin } = require('ucg');

const app = express();
app.use(express.json());

// Initialize UCG plugin
const ucgPlugin = new UCGPlugin({
  mountPath: '/admin',
  autoRegisterRoutes: true
});

app.use('/admin', ucgPlugin.initialize(app));

app.listen(3000, () => {
  console.log('🚀 Server running on http://localhost:3000');
  console.log('📊 UCG Admin at http://localhost:3000/admin');
});

Note: Both patterns are equivalent and fully supported. Use whichever feels more natural for your project.

✨ Features

  • 🔥 Auto Database Config: Automatically creates database configuration during CRUD generation
  • 🔄 Auto Route Mounting: Generated routes are automatically integrated into your app
  • 🔐 Session Management: Robust session handling with proper async initialization
  • 🖥️ CLI & Web Interface: Both command-line and web-based management
  • 🗄️ Multiple ORMs: Support for Sequelize, TypeORM, and Knex
  • 📚 Swagger Documentation: Auto-generated API documentation
  • ✅ Validation: Input validation with Joi
  • 🔗 Relational Data: Complete support for associations and related data

📖 Documentation

Database Configuration

Create a .env file in your project root:

DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database
DB_USER=your_username
DB_PASS=your_password

Available Commands

ncg init                     # Initialize NCG in current project
ncg start                    # Start admin interface
ncg generate:model --table users    # Generate model from table
ncg generate:crud --model User      # Generate CRUD operations
ncg help                     # Show all commands

Plugin Options

const ncgPlugin = ncg({
  mountPath: '/admin',           // Mount path for admin interface
  autoRegisterRoutes: true,      // Auto-mount generated routes
  configDir: '.ncg',            // Configuration directory
  swaggerConfig: {
    title: 'My API',
    version: '1.0.0',
    description: 'API Documentation'
  }
});

🏗️ Generated Structure

UCG generates a complete CRUD API structure:

src/
├── config/
│   └── database.js          # Auto-generated database configuration
├── models/
│   ├── index.js            # Auto-generated models index
│   └── User.js             # Generated model
├── controllers/
│   └── userController.js   # Generated controller
├── services/
│   └── userService.js      # Generated service layer
├── routes/
│   └── userRoutes.js       # Generated routes
├── validators/
│   └── userValidator.js    # Generated validation
└── docs/
    └── swagger/
        └── user.swagger.js  # Generated API docs

🔧 Supported Databases

  • PostgreSQL (Recommended)
  • MySQL/MariaDB
  • SQLite

🔧 Supported ORMs

  • Sequelize (Default)
  • TypeORM
  • Knex.js

📝 API Features

Generated APIs include:

  • GET /api/users - List all users with pagination, filtering, and search
  • GET /api/users/:id - Get user by ID with relational data
  • POST /api/users - Create new user with validation
  • PUT /api/users/:id - Update user with validation
  • DELETE /api/users/:id - Delete user

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Support

  • Issues: GitHub Issues
  • Documentation: Available in the admin interface
  • Examples: Included in the package

Made with ❤️ by the UCG Contributors