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

@voscarmv/apigen

v2.0.1

Published

Postgres DB / Express Backend API generator

Downloads

437

Readme

apigen

A simple, flexible Express backend generator with Drizzle ORM integration.

Installation

npm install @voscarmv/apigen

Basic demo

See a working demo here.

Basic Usage

import { DynamicStoreBackend } from '@voscarmv/apigen';
import { users } from './schema.js'; // Your Drizzle schema
import { eq } from 'drizzle-orm';

// Create backend instance
const backend = new DynamicStoreBackend({
    dbUrl: process.env.DATABASE_URL!,
    port: 3000
});

// Add a public route
backend.route({
    method: 'get',
    path: '/users',
    handler: async (db, req, res) => {
        const allUsers = await db.select().from(users);
        res.json(allUsers);
    }
});

// Add a route with auth middleware
const requireAuth = (req, res, next) => {
    const token = req.headers.authorization;
    if (!token) return res.status(401).json({ error: 'Unauthorized' });
    next();
};

backend.route({
    method: 'post',
    path: '/users',
    middlewares: [requireAuth],
    handler: async (db, req, res) => {
        const newUser = await db.insert(users).values(req.body).returning();
        res.json(newUser[0]);
    }
});

// Start server
backend.listen();
console.log('Server running on port 3000');

API

new DynamicStoreBackend(params)

Creates a new backend instance with pre-configured middleware (CORS, Helmet, Morgan, JSON parsing).

Parameters:

  • dbUrl (string): PostgreSQL connection string
  • port (number): Port to run server on
  • corsOpts (optional): CORS configuration object

backend.route(params)

Adds a new route to the server.

Parameters object:

  • method: HTTP method ('get' | 'post' | 'put' | 'delete' | 'patch')
  • path: Route path (e.g., /users/:id)
  • handler: Request handler function (db, req, res) => Promise<void>
  • middlewares (optional): Array of Express middleware functions

backend.listen()

Starts the Express server on the configured port.

Complete Example

import { DynamicStoreBackend } from '@voscarmv/apigen';
import { tasks } from './schema.js';
import { eq } from 'drizzle-orm';

const backend = new DynamicStoreBackend({
    dbUrl: process.env.DATABASE_URL!,
    port: 3000
});

// Get all tasks
backend.route({
    method: 'get',
    path: '/tasks',
    handler: async (db, req, res) => {
        const allTasks = await db.select().from(tasks);
        res.json(allTasks);
    }
});

// Get task by ID
backend.route({
    method: 'get',
    path: '/tasks/:id',
    handler: async (db, req, res) => {
        const task = await db
            .select()
            .from(tasks)
            .where(eq(tasks.id, req.params.id));
        res.json(task[0]);
    }
});

// Create task with API key auth
const apiKeyAuth = (req, res, next) => {
    if (req.headers['x-api-key'] !== 'secret') {
        return res.status(403).json({ error: 'Forbidden' });
    }
    next();
};

backend.route({
    method: 'post',
    path: '/tasks',
    middlewares: [apiKeyAuth],
    handler: async (db, req, res) => {
        const newTask = await db.insert(tasks).values(req.body).returning();
        res.json(newTask[0]);
    }
});

backend.listen();

Using Multiple Middlewares

You can chain multiple middlewares for complex authentication, validation, or processing:

import multer from 'multer';

const upload = multer({ storage: multer.memoryStorage() });

backend.route({
    method: 'post',
    path: '/upload',
    middlewares: [requireAuth, upload.single('file'), validateFile],
    handler: async (db, req, res) => {
        // Access uploaded file via req.file
        res.json({ success: true, filename: req.file?.originalname });
    }
});

Features

  • 🚀 Quick Express + Drizzle setup
  • 🔒 Built-in security with Helmet
  • 🌐 CORS support out of the box
  • 📝 Request logging with Morgan
  • 🔧 Flexible middleware support
  • 💾 Direct database access in handlers
  • 📦 TypeScript support