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-ts-base

v1.0.1

Published

Provides a few base classes that can be use to set up a node webserver.

Readme

Express.JS TypeScript Base

This package provides a few helpers classes that aid in setting up an express server quickly and in an object-orientated manner. This package can also be used in JavaScript.

NodeServer

This class is similar to the default express app.js setup that the express-generator cli will output, however it uses an abstract class instead. In order to use it, you should extend it like so:

class AppServer extends NodeServer {
  ...[method/property definitions]
}

It provides a few optional properties and methods that can be implemented in order to customise how the server runs. This is the interface that defines all the optional items (copied from the source):

export interface NodeServer {
  /**
   * If given, adds the directory as an express static directory
   * while initialising the express middleware. This value is used exactly.
   */
  staticBase?: string;
  /**
   * If given, adds the favicon middleware while initalising the express
   * middleware. This value is used exactly.
   */
  faviconPath?: string;
  /**
   * If true, disables the standard middleware loading step.
   */
  disableStdMiddleware?: boolean;
  /**
   * If given, adds a catch-all route after calling the router setup
   * to catch and respond to all uncaught requests.
   */
  useCatchAll?: boolean;

  /**
   * If defined, this method is fired just before any configuration is done
   * in the `configure` method.
   * This method should be used to install logger middleware.
   */
  preConfigure?(): Promise<void>;
  /**
   * This method should be used to load in custom middleware and the routes that
   * this application will use.
   */
  mainConfigure?(): Promise<void>;
  /**
   * If defined, this method is fired after all configuration is done
   * in the `configure` method.
   */
  postConfigure?(): Promise<void>;
}

Running the server

To run the server, simply instantiate it, call the configure method and then the listen method. It will deal with the options in the configure call, and will create the webserver in the listen call.

(async () => {
  const app = new AppServer();
  await app.configure();
  app.listen();
})().catch(err => {
  console.error(err);
  process.exitCode = 1;
});

Controller

This class provides a bit of bootstrapping to allow an object-orientated routing system. Each implementing class should always implement the following method:

protected abstract linkRoutes(router: Router): void;

Then, when using the controller as a route, you can do the following in the AppServer.mainConfigure method:

this.express.use('/api', new ApiController().router());

The ApiController class can also specify sub-routes in the exact same manner, allowing fully nested routes with a clear hierarchy and encapsulated logic. The method of instantiation is entirely optional as well, you could instead use dependency injection and have the sub-controllers be injected already constructed into the controller, and then just call .router() in the linkRoutes method. This would allow the controllers to also have services be injected if you needed.