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

doppio

v0.3.3

Published

A small server container to make managing and testing server processes easier.

Downloads

26

Readme

doppio

Build Status

Doppio is a small "server container" for Node.JS web applications that makes managing the server process more convenient and testable.

Basic Usage

npm install doppio

Doppio works by wrapping your application with an http server. This is basically what the Express documentation recommends for configuring an application with HTTPS. Doppio just makes this process easier to manage and test. In the simplest case you can wrap your app and the server will start automatically:

var doppio = require("doppio");

var server = doppio({ port: 8080 }, app);

Usage Details

doppio([options], [handler])

  • options - Optional. Options to configure the server instance.
  • handler - Optional. The request handler for the server. This typically something like an Express app.

Creates a new server instance. By default, the server starts listening for requests automatically. The following configuration options are available:

  • autostart - Defaults to true. If true, the server will start automatically unless NODE_ENV is 'test'.
  • cert - The contents of the public certificate to use for HTTPS. See the Node HTTPS documentation for more information.
  • key - The contents of the private key to use for HTTPS. See the Node HTTPS documentation for more information.
  • hostname - Defaults to 'localhost'. Sets the hostname that the server will be running at. This is used by server.url().
  • path - Defaults to '/'. Sets the base path for all URLs computed using server.url().
  • port - Defaults to 0. The default port to use if a port is not provided to server.start(). If 0 is provided, an arbitrary open port will be assigned. For cases involving a proxy, a port pair can be specified (see server.start() for more details).
  • scheme - Defaults to 'http'. Must be either 'http' or 'https'. When running with 'https', a certifacate and key must also be specified. If running behind a proxy it is possible to specify a scheme pair as follows: { private: "http", public: "https" }. The public scheme will be reflected by server.url().

doppio.loadPlugin([id...])

  • id - Optional. One ore more module IDs of the plugins to load (Node.JS modules).

Loads plugins to process server configuration options. When multiple plugins are loaded, they will be processed in the order specified. See the "Plugins" section for more details.

doppio.unloadPlugins()

Unloads all plugins restoring Doppio to the default behavior.

server.server()

Returns a Node HTTP API instance for the Doppio instance. This is useful for integrating with external tools like Socket.IO.

server.start([port], [callback])

  • port - Optional. The port that the server should listen on. If this is not provided, the default port is used (this is typically an arbitrary open port). In the case that the server should bind to a different port than the client will connect on, a pair can be specified as follows: { private: 54321, public: 80 }. The public port will be reflected by server.url().
  • callback Optional. If provided, the callback will be automatically subscribed to the ready and error events.

Starts listening on a port. It is an error to try to start a server that is already listening. Returns a chainable reference to the server.

server.stop([callback])

  • callback Optional. If provided, the callback will be automatically subscribed to the stopped and error events.

Stops listening for requests. Returns a chainable reference to the server.

server.url([path])

  • path Optional. Resolve the given path against the server base URL and return the fully qualified URL.

Returns the fully qualified URL of the application. An error will be thrown if server.url() is called while the server is not listening.

Event: 'error'

function (error) { }

Emitted when an error occurs with the server.

Event: 'ready'

function () { }

Emitted when the server is ready to process requests.

Event: 'stopped'

function () { }

Emitted when the server closes and finishes handling all requests.

Plugins

Doppio plugins can be used to change how server options are handled. This can be useful for things like adding runtime specific logic. A Doppio plugin is just a Node module that exports a function that takes an options hash as its only argument and returns a new options hash (see the doppio() section for more info on the available options). Each time a new server instance is created, the plugins are invoked in the order they were loaded in. Each plugin is passed the options returned from the previous plugin as its argument. For example, the default option logic is equivalent to the following plugin code:

module.exports = function (options) {
    options.autostart = "autostart" in options ? options.autostart : true;
    options.hostname  = options.hostname || "localhost";
    options.path      = options.path || "/";
    options.port      = "port" in options ? options.port : 0;
    options.scheme    = options.scheme || "http";
    return options;
};