npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@eduardomagaldi/crudy

v1.0.2

Published

A CRUD generator for Express.js with PostgreSQL - automatically detects schemas and handles relations

Readme

Crudy

A CRUD generator for Express.js with PostgreSQL that automatically detects table schemas and handles relations.

Features

  • 🚀 Auto-detect schemas from PostgreSQL database (lazy loading - no database calls on creation)
  • 🔗 Automatic relation detection from foreign keys
  • 📦 Multi-table support - generate CRUD for multiple tables at once
  • 🔍 Related data inclusion - GET requests automatically include related records
  • 🛡️ Smart delete protection - shows which records are blocking deletions
  • Zero configuration - just pass table names

Installation

npm install github:eduardomagaldi/crudy
npm install pg express

Quick Start

const express = require('express')
const { Pool } = require('pg')
const createCrudyMulti = require('crudy')

const pool = new Pool({
  user: 'your_user',
  host: 'localhost',
  database: 'your_database',
  password: 'your_password',
  port: 5432,
})

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

// ⚡ No await needed! createCrudyMulti is synchronous
// Schemas are loaded lazily on first request
const handlers = createCrudyMulti(['users', 'addresses', 'purchases'], pool)

// Response middleware
const sendResponse = (req, res) => {
  const status = res.locals.crudyStatus || 200
  const result = res.locals.crudyResult
  if (status === 204) return res.status(204).send()
  res.status(status).json(result)
}

// Set up routes
app.get('/users', handlers.users.handleGetAll, sendResponse)
app.get('/users/:id', handlers.users.handleGet, sendResponse)
app.post('/users', handlers.users.handleCreate, sendResponse)
app.put('/users/:id', handlers.users.handleUpdate, sendResponse)
app.delete('/users/:id', handlers.users.handleDelete, sendResponse)

// Repeat for other tables: handlers.addresses.*, handlers.purchases.*

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000')
})

How It Works

Lazy Schema Loading

No database calls on creation! Schemas are automatically loaded and cached in memory on the first request. This means:

  • ✅ Instant handler creation (synchronous, no await)
  • ✅ Schemas cached as singleton (one query per table)
  • ✅ Fast subsequent requests

Schema Auto-Detection

Crudy automatically detects:

  • Column types, primary keys, foreign keys, auto-increment, required/optional fields

Relation Detection

Relations are automatically detected from:

  1. Foreign key constraints
  2. Column patterns (e.g., user_idusers table)

Relation Types:

  • belongsTo - Included as singular property: address.user
  • hasMany - Included as plural property: user.addresses

API

createCrudyMulti(tableNames, db)

Creates CRUD handlers for multiple tables. Synchronous - no await needed!

Parameters:

  • tableNames (string[]) - Array of table names
  • db (pg.Pool) - PostgreSQL connection pool

Returns: Object with table names as keys, each containing:

  • handleGetAll(req, res, next) - Get all records
  • handleGet(req, res, next) - Get single record by ID
  • handleCreate(req, res, next) - Create new record
  • handleUpdate(req, res, next) - Update record by ID
  • handleDelete(req, res, next) - Delete record by ID
  • tableName - Table name
  • schema - Schema object (available after first request)

Response Format

GET with Relations

{
  "id": 1,
  "email": "[email protected]",
  "addresses": [{ "id": 1, "street": "123 Main St", "user_id": 1 }],
  "user": { "id": 1, "email": "[email protected]" }
}

DELETE with Relations

If deleting a record referenced by others:

{
  "error": "Cannot delete: this record is referenced by other records",
  "details": "2 record(s) in 'addresses' table (IDs: 1, 2)"
}

Status: 409 Conflict

Query Parameters

Filter results using query parameters:

GET /[email protected]&is_active=true

Error Handling

Handlers set response data in res.locals:

  • res.locals.crudyStatus - HTTP status code
  • res.locals.crudyResult - Response data or error object

Status codes: 200 (Success), 201 (Created), 204 (No Content), 404 (Not Found), 409 (Conflict), 500 (Server Error)

Requirements

  • Node.js 14+
  • PostgreSQL database
  • pg package (peer dependency)
  • express package

License

ISC