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

osh-serve

v0.0.0

Published

openscihub.org: serve osh-pages and osh-paths

Downloads

3

Readme

Serve

Serve a collection of Pages and Paths in Node.js. Most importantly, it handles interfacing with Dynapack for you so that you can (almost) forget about compilation steps and whatnot (at least that's the hope).

Installation

npm install osh-serve

Example

var serve = require('osh-serve');

var app = serve({
  dir: __dirname + '/app',
  paths: [ // modules (relative to dir) that export a Path
    'api/user',
    'api/recipe',
    'api/favorite-joke'
  ],
  pages: [ // modules (relative to dir) that export a Page
    'user',
    'signup',
    'submit-favorite-joke'
  ]
});

// app is an Express instance.

app.on('serving', function() {
  app.listen(3333);
});

Documentation

This module exports a single function that returns an Express instance. The function is async b/c we (usually) have to bundle javascript with Dynapack; the returned Express instance (which is an EventEmitter) emits the 'serving' event when all javascript has been bundled and all middleware has been attached. If an error occurs, the 'error' event will emit.

Configuration

The serve function accepts a single configuration object with the following properties.

Sample config with default values:

{
  app: require('express')(),
  dir: process.cwd(),
  paths: [],
  pages: [],
  scripts: {
    serve: true,
    output: require('temp').track().mkdirSync('__bundle'),
    prefix: '/'
  }
};

app {Express}

Optional. If provided, all Page/Path middleware will be mounted to it. If undefined, osh-serve will create its own.

dir {String}

The base directory for all pages and paths; this should be an absolute path. Defaults to current working directory.

paths {Array<Path|String>}

Serve these Paths. An array element can be a Path instance or a string pointing to a module that exports a Path instance. The string can be relative to the 'dir' setting.

pages {Array<String>}

Each array element is a string pointing to a module that exports a Page instance. The string can be relative to the 'dir' setting.

Beware that pages will not be mounted until after the 'serving' event fires on the returned Express app.

scripts {Object}

Options for module bundling; most of the properties on this object are passed directly to Dynapack. The properties on the scripts object are:

scripts.serve {Boolean}

If true, javascript bundles are served via this Express app under the scripts.prefix route using the serve-static package. Default: true.

scripts.prefix {String}

(Dynapack) This is prepended to each script name generated by Dynapack. If scripts.serve is true, this prefix is also used to serve generated javascript bundles. If you send your bundles to a CDN, then the prefix should include the protocol, hostname, etc.

If prefix does not start with '/', then it is assumed that the scripts are delivered by an external server. In this case the scripts.serve setting is assumed false.

Default: '/'

scripts.output {String}

(Dynapack) Where to save the generated bundles. If left unspecified, and scripts.serve is true, we save them in a temporary directory. If unspecified and scripts.serve is false, no bundles are created and your app will serve static pages.

License

MIT