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

putitdigital-api-express

v0.1.3

Published

Express API scaffolding package that auto-generates folder structure based on resource.json

Downloads

1,974

Readme

putitdigital-api-express

A comprehensive Express.js API scaffolding package that automatically generates a complete folder structure with authentication, database configuration, and boilerplate files based on a resource.json configuration file.

Installation

npm install putitdigital-api-express

How it works

When installed, this package runs a postinstall script that automatically:

  1. Checks for a resource.json file in your project root
  2. Creates template files for .env, .request.rest, and server.js
  3. If resource.json contains a "tables" key, scaffolds the complete API structure with:
    • Models with database queries
    • Controllers for business logic
    • Routes for HTTP endpoints
    • Authentication middleware
    • Database configuration
    • Express server setup

Quick Start

Step 1: Install the package

npm install putitdigital-api-express

The postinstall script will automatically create template files in your project root.

Step 2: Create or update resource.json

Define your API resources by table name:

{
  "tables": {
    "users": {},
    "posts": {},
    "comments": {}
  }
}

Step 3: Configure your environment

Edit the generated .env file with your database credentials:

DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=yourdb
JWT_SECRET=your_secret_key_here
PORT=3000

Step 4: Run the scaffolding

Simply reinstall to trigger scaffolding:

npm install

Or manually run:

node node_modules/putitdigital-api-express/lib/scaffold.js

Step 5: Start your server

node server.js

Generated folder structure

project-root/
├── resource.json           # API configuration
├── .env                    # Environment variables
├── .request.rest           # REST client requests
├── server.js               # Express app entry point
├── API/
│   ├── models/
│   │   ├── usersModel.js
│   │   ├── postsModel.js
│   │   └── commentsModel.js
│   ├── controllers/
│   │   ├── usersController.js
│   │   ├── postsController.js
│   │   └── commentsController.js
│   ├── routes/
│   │   ├── usersRoutes.js
│   │   ├── postsRoutes.js
│   │   └── commentsRoutes.js
│   ├── middleware/
│   │   └── authMiddleware.js
│   └── config/
│       └── db.js           # Database connection pool
└── node_modules/
    └── putitdigital-api-express/

Features

  • Auto-scaffolding - Generates complete API structure on install
  • Authentication - Built-in JWT-based authentication middleware
  • Password Hashing - Bcrypt integration for secure password storage
  • Database Layer - MySQL2 connection pooling for MySQL/MariaDB
  • Environment Variables - dotenv support for configuration
  • Models & Controllers - MVC pattern boilerplate
  • Express Routes - RESTful endpoint structure
  • Cookie Parser - Middleware for parsing cookies
  • Safe Generation - Skips files that already exist
  • Idempotent - Safe to run multiple times

Generated Endpoints

For each table in resource.json, the following RESTful endpoints are generated:

  • GET /api/{table} - List all records
  • GET /api/{table}/:id - Get record by ID
  • POST /api/{table} - Create new record
  • PUT /api/{table}/:id - Update record
  • DELETE /api/{table}/:id - Delete record

Example: Users table

GET    /api/users              - Fetch all users
GET    /api/users/:id          - Fetch user by ID
POST   /api/users              - Create new user
PUT    /api/users/:id          - Update user
DELETE /api/users/:id          - Delete user

Dependencies

  • express (^5.2.1) - Web framework
  • mysql2 (^3.22.5) - MySQL database driver
  • bcrypt (^6.0.0) - Password hashing
  • jsonwebtoken (^9.0.3) - JWT authentication
  • dotenv (^17.4.2) - Environment variable management
  • cookie-parser (^1.4.7) - Cookie parsing middleware

Authentication

The generated authMiddleware.js provides JWT-based authentication. Use it to protect routes:

const authMiddleware = require('./API/middleware/authMiddleware');

app.get('/api/protected-route', authMiddleware, (req, res) => {
  // Protected route - user is in req.user
  res.json({ user: req.user });
});

Generated Files Details

Models (API/models/*.js)

  • Database query functions with callbacks
  • Password hashing integration
  • Email lookup and other utility queries

Controllers (API/controllers/*.js)

  • Request handlers
  • Business logic
  • Error handling

Routes (API/routes/*.js)

  • Express router configuration
  • HTTP method mapping to controllers

Config (API/config/db.js)

  • MySQL connection pool setup
  • Environment variable integration

Middleware (API/middleware/authMiddleware.js)

  • JWT token verification
  • User authentication

Server (server.js)

  • Express app initialization
  • Route mounting
  • Server startup on configured PORT

Tips

  • Use .request.rest for testing API endpoints (requires REST Client extension in VS Code)
  • Update resource.json with all tables before installing
  • Review generated code - it's a starting template, customize as needed
  • Add business logic to controllers after generation
  • Modify models to match your exact database schema

License

MIT

  • DELETE /api/users/:id - Delete user

Notes

  • The postinstall script runs automatically when the package is installed
  • It only creates files if they don't already exist
  • If resource.json is not found, scaffolding is skipped silently
  • If resource.json doesn't contain a "users" resource, scaffolding is skipped

Publishing

To publish this package to npm:

cd putitdigital-api-express
npm publish --otp=<your-2fa-code>

License

MIT

resource.json example

{ "tables": { "user": { "columns": [ "name", "email", "password" ], "action":[ "create", "read", "findByEmail", "update", "delete" ] },"product": { "columns": [ "name", "description", "price" ], "action":[ "create", "read", "findByEmail", "update", "delete" ] } } }