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

towers-express

v1.1.2

Published

Fast and simple express api creation with custom user's functions, built with TypeScript.

Readme

Towers Express Library

A library to simplify building APIs in Node.js with Express. It allows you to define functions as endpoints, authenticate users, check permissions, upload files, and serve over HTTP and HTTPS with quick setup.


✨ Features

  • 📦 Dynamic function registration as endpoints.
  • 🔐 Customizable authentication and permissions.
  • 📁 File upload support with multer.
  • 🔁 Supports both GET and POST with the same endpoint.
  • 🌐 Easy setup for both HTTP and HTTPS servers.
  • 🚀 Built-in CORS middleware.

📦 Installation

npm install towers-express

Make sure you have express and multer as dependencies.


🚀 Basic Usage

1. Create the server

import { TowersExpress, TowersFunctionsController } from "towers-express";

const server = new TowersExpress("/api/functions", 3000);

// Optional: Configure SSL
server.configureSSL(3443, {
  keyPath: "./ssl/key.pem",
  certPath: "./ssl/cert.pem"
});

// Start the server
server.start({
  allowOrigin: "http://localhost:5173", // CORS
  onHttpStart: () => console.log("HTTP started"),
  onHttpsStart: () => console.log("HTTPS started")
});

2. Register functions

TowersFunctionsController.registerFunction("helloWorld", {
  method: async (req, res) => {
    res.json({ message: "Hello world!" });
  },
});

3. Call functions

  • GET: GET /api/functions/helloWorld?name=John
  • POST: POST /api/functions/helloWorld with JSON in the body.

🛡️ Authentication and Permissions

You can define functions to authenticate users and check permissions.

// Define how to authenticate users (e.g., with token)
TowersFunctionsController.setAuthUserFunction(async (req) => {
  const token = req.headers.authorization;
  if (token === "secret") return { id: 1, name: "Admin" };
  return null;
});

// Define how to check permissions
TowersFunctionsController.setCheckRightsFunction(async (user, rights, req) => {
  if (!user || !user.id) return "Unauthorized";
  if (!user.isAdmin && rights.includes("admin")) return "Insufficient permissions";
});

Register a protected function

TowersFunctionsController.registerFunction("adminOnly", {
  method: async (req, res, user) => {
    res.send(`Hello, ${user.name}, you have admin access.`);
  },
  auth: true,
  rights: ["admin"]
});

📤 File Uploads

The library uses multer to handle file uploads:

TowersFunctionsController.registerFunction("uploadFile", {
  method: async (req, res) => {
    const file = req.file; // For single file
    res.send(`Received file: ${file.originalname}`);
  },
});

For multiple files:

TowersFunctionsController.registerFunction("uploadFiles", {
  method: async (req, res) => {
    const files = req.files;
    res.send(`Received ${files.length} files`);
  },
  maxFiles: 5
});

🔍 Available APIs

TowersExpress

| Method | Description | |--------|-------------| | start(options) | Starts the HTTP and/or HTTPS server | | configureSSL(port, { keyPath, certPath }) | Configure HTTPS | | applyMiddleware(...middlewares) | Add custom middleware |

TowersFunctionsController

| Method | Description | |--------|-------------| | registerFunction(name, config) | Register a new API function | | getFunction(name) | Retrieve a registered function | | callFunction(name, req, res) | Call a function (used internally) | | setAuthUserFunction(func) | Define how to authenticate users | | setCheckRightsFunction(func) | Define how to check user permissions |


📄 Full Example

const server = new TowersExpress("/api", 3000);

TowersFunctionsController.setAuthUserFunction(async req => ({ id: 1, name: "user" }));

TowersFunctionsController.registerFunction("echo", {
  method: async (req, res) => {
    res.json({ youSent: req.body });
  },
});

server.start({});

📃 License

MIT License