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

servbot

v0.2.6

Published

A small dev server script for local static site development

Downloads

377

Readme

servbot

A small dev server for local static site development. Essentially a wrapper around http.Server. Fork of servor.

import servbot from 'servbot';

const server = servbot({
    root: './public/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);

This is an opinionated fork with some intentional exclusions and smaller scope, and some ideas taken from nativew/serve.

Install

npm install servbot --save-dev

Usage

See types in index.d.ts. servbot accepts a single argument, ServbotOptions; and returns an instance of ServbotServer. See below for the default options.

import servbot from 'servbot';

const server = servbot({
    // root: string
    // Directory to serve. Relative to process.cwd().
    root: '.',

    // reload: boolean
    // Flag to enable manual reload.
    reload: false,

    // fallback: string
    // Filename to fallback to for single-page applications. Relative to `root`.
    // Leaving this empty assumes you are not serving a single-page application
    fallback: '',

    // ignores: RegExp[]
    // *Only applicable when `fallback` is provided and `ignores` is not an empty array*.
    // A list of patterns to *not* route to your fallback.
    // Useful when you want to be able to route non-filetypes to your SPA ("/foo/routename.hi")
    // But otherwise, want to "ignore" routes that should be static files ("/main.css", "/js/jquery.js")
    ignores: [],

    // credentials: object
    // TLS Credentials. Providing these enables an HTTPS server.
    // See https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener
    credentials: undefined,

    // verbose: boolean
    // Flag to enable server response logging.
    verbose: true
});

// Start server on port 8080
server.listen(8080);

// Close server from new connections
// https://nodejs.org/api/net.html#serverclosecallback
server.close((err) => {
    if (err) process.exit();
});

Using manual reload

Instead of including a filewatcher to automatically reload your app on file changes, servbot includes a manual reload feature. Most modern front-end development build tools already include a built-in watch feature (esbuild, rollup, webpack, parcel, etc.) that can be leveraged by servbot. For an example with rollup, see here.

Outside of build tools, you can also use something like cheap-watch or watchlist. See below for an example using watchlist:

import servbot from 'servbot';
import { watch } from 'watchlist';

const server = servbot({
    root: './example/static/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);

(async () => {
    await watch(['./example/static/'], async () => {
        console.log('change detected! reloading...');
        server.reload();
    });
})();

To-Do

  • Better tests for SPA example
  • HTTP/2 support