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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mvarble/http-server

v1.0.2

Published

An HTTP server that has various routes I repeatedly use.

Downloads

2

Readme

HTTP Server

This is an npm package which generates Express apps with middleware I commonly use, along with HTTP servers to serve them. The module exports an object with the following properties.

createApp

This is a function which returns an Express app with associated middleware.

Signature

  const expressApp = createApp(); // Express app with the defaults
  const anotherExpressApp = createApp({
      static: {
          path: '/static', 
          src: process.cwd() + '/dist', 
          close: true 
      },
  });

The function takes in an optional object argument, which can have the following keys.

  • static: This allows us to have HTTP routes corresponding to static files in the filesystem. To turn this functionality off, provide static: {}. Otherwise, this is an object with the following keys.
    • path: This is a string corresponding to the HTTP route of the static directory. Default 'static'.
    • src: This is a string corresponding to the path of the static directory in the filesystem. Default '$PROJECT_DIR/dist'.
    • close: This is a boolean corresponding to if we want HTTP routes not corresponding to files in the filesystem to to 404. Default true.

createHTTP

This is a function which starts a server on an available port and returns it.

Signature

  const server = createServer();
  const ratServer = createServer({ port: 8666, portRetries: 10, name: 'Rat' });

The function takes in an optional object argument, which can have the following keys.

  • port: This is a number corresponding to the port the server is on. Default 8666.
  • portRetries: This is a nonnegative integer corresponding to how many times we increase the port number and retry on EADDRINUSE errors. Default 10.
  • name: This is a string that literally only serves for displaying in the log. Default undefined.

sqliteSessionMiddleware

This is a function which returns middleware for connecting session storage to a sqlite database.

Signature

  someExpressApp.use(sqliteSessionMiddleware({
      secret: 'thesecretkeyisRATS',
      sqliteDir: process.cwd(),
      sqliteName: 'database.db'
  }));
  anotherExpressApp.use(sqliteSessionMiddleware('thesecretkeyisRATS'));

The function takes in a single argument that is either a string or an object. The string would take place of the field secret in the object with the following fields.

  • secret (required): This is a string corresponding to the secret passphrase for session storage.
  • sqliteDir: This is a string corresponding to the directory in which the sqlite database file is stored. Default $PROJECT_DIR.
  • sqliteName: This is a string corresponding to the filename of the sqlite database. Default is 'database.db'.