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

express-web-tools

v1.0.4

Published

A lightweight framework-style library for Express applications using Mongoose. Includes reusable classes such as CrudController, CrudRouter, MongooseSchema, and JWT helpers to enforce consistent API structure and reduce boilerplate.

Readme

express-web-tools

A lightweight framework-style library for Express applications using Mongoose. Includes reusable classes such as CrudController, CrudRouter, MongooseSchema, and JWT helpers to enforce consistent API structure and reduce boilerplate.

Installation

To install express-web-tools, use npm:

npm install express-web-tools

Usage

CrudController

A base controller for CRUD operations on Mongoose models.

import { CrudController } from 'express-web-tools';
import { Model, Document } from 'mongoose';

interface MyDocument extends Document {
    name: string;
    // ... other properties
}

class MyController extends CrudController<MyDocument> {
    constructor(model: Model<MyDocument>) {
        super(model);
    }
    // You can override or add custom methods here
}

// Example:
// const myController = new MyController(MyModel);
// const newItem = await myController.create({ name: "Test Item" });

CrudRoutes

Generates Express routes for CRUD operations using a CrudController.

import { CrudRoutes, CrudController } from 'express-web-tools';
import { Router } from 'express';
import { Model, Document } from 'mongoose';

interface MyDocument extends Document {
    name: string;
    // ... other properties
}

// Assume MyModel is a Mongoose Model and myController is an instance of CrudController<MyDocument>
// const myCrudRoutes = new CrudRoutes<MyDocument>('/api/my-resource', myController);
// const router: Router = myCrudRoutes.publish();
// app.use('/', router);

ExpressServer

A utility class to set up and manage an Express server.

import { ExpressServer } from 'express-web-tools';
import express from 'express';

const app = new ExpressServer();

// Add middleware
app.addMiddleware(express.json());

// Set up views (optional)
app.views('pug', './views');

// Add routes
// app.addRoute('/api', myCrudRouter);

// Start the server
// app.start(3000);

fsLogger

A file system-based logger with archiving capabilities.

import { fsLogger } from 'express-web-tools';

fsLogger.Log('This is a log message.');
fsLogger.Log('User logged in', { userId: '123', ip: '192.168.1.1' });

// To archive logs (e.g., weekly, as configured internally)
// await fsLogger.Archive();

Token

Utility for generating and verifying JWT tokens.

import { Token } from 'express-web-tools';

const userPayload = { id: 'user123', role: 'admin' };
const jwtToken = Token.generate(userPayload, '1h'); // Token expires in 1 hour

try {
    const decoded = Token.verify(jwtToken);
    console.log('Decoded token:', decoded);
} catch (error) {
    console.error('Token verification failed:', error.message);
}

Mutate

Deep clones an object using JSON serialization.

import { Mutate } from 'express-web-tools';

const originalObject = { a: 1, b: { c: 2 } };
const clonedObject = Mutate(originalObject);

clonedObject.b.c = 3;
console.log('Original:', originalObject); // { a: 1, b: { c: 2 } }
console.log('Cloned:', clonedObject);     // { a: 1, b: { c: 3 } }

HttpError

A custom HTTP error class.

import { HttpError } from 'express-web-tools';

try {
    throw new HttpError('Resource not found', 404);
} catch (error) {
    if (error instanceof HttpError) {
        console.error(`HTTP Error: ${error.message}, Code: ${error.code}`);
    } else {
        console.error('An unexpected error occurred:', error);
    }
}

MongooseModel

A wrapper for Mongoose schemas and models, adding common fields and hooks.

import { MongooseModel } from 'express-web-tools';
import mongoose, { Schema, Document } from 'mongoose';

interface UserDocument extends Document {
    username: string;
    email: string;
}

const userSchema = new Schema({
    username: { type: String, required: true },
    email: { type: String, required: true, unique: true },
});

const userMongooseModel = new MongooseModel<UserDocument>(
    'User',
    userSchema
);

const User = userMongooseModel.model(); // This is your Mongoose Model

API Reference

The library exposes the following main components:

  • fsLogger: A singleton instance for file system logging.
  • CrudController<T extends Document>: Generic class for Mongoose CRUD operations.
  • CrudRoutes<T extends Document>: Generic class to generate Express routes for CRUD.
  • MongooseModel<T extends Document>: Generic class to define Mongoose models with extended features.
  • ExpressServer: Class to set up and manage an Express application.
  • HttpError: Custom error class for HTTP-specific errors.
  • Token: Object containing generate and verify functions for JWT.
  • Mutate: Function for deep cloning objects.

Keywords

express, mongoose, crud, crud-controller, crud-router, rest-api, api-framework, jwt, authentication, authorization, middleware, schema, validation, boilerplate-reduction, nodejs

License

This project is licensed under the ISC License.